[mpl] Working with map, copy and back_inserter
I'm trying to implement a compile-time topological sort of the DAG
representing a certain dependency relationship between my classes.
One of the data structures I can use to implement topological sort is a
map, so I'm trying to use mpl::map using mpl::size_t<> as key. The
documentation doesn't define key equality for mpl::map, but I assume it's
effectively std::is_same<>. If so, I think I have a problem. In the
following code, the last two lines fail static_assert().
The essence of the problem is that my attempt to construct/build my keys
using copy with back_inserter does not give me a mpl::vector<> of
mpl::size_t<> that is_same to Count, the expected value. It does give me a
sequence, and the elements have the right value and value_type but they are
not is_same to the expected size_t<> types. So, if I use the elements
together with the size_t<> in an mpl::map, won't they be considered to be
different keys?
Josh
#include
AMDG On 02/05/2017 02:42 AM, ☂Josh Chia (謝任中) wrote:
<snip> The essence of the problem is that my attempt to construct/build my keys using copy with back_inserter does not give me a mpl::vector<> of mpl::size_t<> that is_same to Count, the expected value. It does give me a sequence, and the elements have the right value and value_type but they are not is_same to the expected size_t<> types. So, if I use the elements together with the size_t<> in an mpl::map, won't they be considered to be different keys?
Yes. If you want to use a map this way, you'll
need to normalize the keys for insertion.
something like this should do the trick:
template<class T>
struct as_size_t { typedef mpl::size_t
participants (2)
-
Steven Watanabe
-
☂Josh Chia (謝任中)