Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Re: questions about concept_map<Stack<vector> >

From: TheChao (jaroslov_at_[hidden])
Date: 2007-03-04 20:34:53


You have declared all of your Stack functions as non-methods, i.e.
rewrite foo like this:

template <Stack T>
void foo ()
{
  T stk;
  push (stk, 1);
  assert (!(empty(stk));
  pop (stk);
  // etc.
}

Note that Stack T makes no assumptions about integral types, so this
is bad-code anyways: it assumes that value_type is convertible to
Integral.

You probably want this for your concept:

concept Stack<typename T> {
   typename value_type = T::value_type;
   where Assignable<value_type> && CopyConstructible<value_type> &&
DefaultConstructible<value_type>;
   // Adobe et al. call this 'Regular'
   void T::push ();
   value_type T::top () const;
   void T::pop ();
   bool T::empty () const;
}

Note that if your concept_map to this concept is anything other than
nominative, i.e. if you have to 'add' a member function to meet the
requirements, it will fail in ConceptGCC5. It may or may not work from
the SVN.

-j.

On 3/4/07, Martin Sebor <sebor_at_[hidden]> wrote:
> I'm experimenting with the Stack<std::vector<T> > concept map
> from N2081 (see my code below) and I'm getting errors I don't
> understand. Can someone help me see what I'm doing wrong?
>
> The errors are:
>
> z.cpp: In function 'void foo()':
> z.cpp:26: error: 'struct T' has no member named 'push'
> z.cpp:27: error: 'struct T' has no member named 'empty'
> z.cpp:28: error: 'struct T' has no member named 'top'
> z.cpp:29: error: 'struct T' has no member named 'pop'
> z.cpp:30: error: 'struct T' has no member named 'empty'
>
> Also, I'm wondering why it is desirable to require the author
> of the concept map to define value_type and empty() when vector
> provides identical members in its own interface.
>
> Thanks
> Martin
>
> #include <vector>
>
> concept Stack<class T> {
> typename value_type;
> T::T ();
> void push (T&, value_type);
> void pop (T&);
> value_type top (const T&);
> bool empty (const T&);
> };
>
> template <class T>
> concept_map Stack<std::vector<T> > {
> typedef T value_type;
> void push (std::vector<T> &v, const value_type &x) { v.push_back (x); }
> void pop (std::vector<T> &v) { v.pop_back (); }
> value_type top (const std::vector<T> &v) { return v.back (); }
> bool empty (const std::vector<T> &v) { return v.empty (); }
> };
>
> template <Stack T>
> void foo ()
> {
> T stk;
> stk.push (1);
> assert (!stk.empty ());
> assert (1 == stk.top ());
> stk.pop ();
> assert (stk.empty ());
> }
>
> int main ()
> {
> foo<std::vector<int> >();
> }
> _______________________________________________
> ConceptGCC mailing list
> ConceptGCC_at_[hidden]
> http://www.osl.iu.edu/mailman/listinfo.cgi/conceptgcc
>