[ConceptGCC] |
ConceptGCC :questions about concept_map<Stack<vector> > |
From: Martin Sebor (sebor_at_[hidden])
Date: 2007-03-04 20:22:45
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> >();
}