C++ Template Metaprogramming
Solutions to the exercises throughout the book
|
Find the smallest type in a sequence with boost::mpl::copy
.
More...
Files | |
file | exercise-6-0.hpp |
Solution to Exercise 6-0. | |
Namespaces | |
namespace | anonymous_namespace{chapter-6.cpp}::test_6_0 |
Tests functionality from Exercise 6-0. | |
namespace | exercise_6_0 |
Encapsulate solution for Exercise 6-0. | |
Find the smallest type in a sequence with boost::mpl::copy
.
6-0. Use mpl::copy with a hand-built inserter to write a smallest metafunction that finds the smallest of a sequence of types. That is: BOOST_STATIC_ASSERT(( boost::is_same< smallest< mpl::vector<int[2], char, double&> >::type, char >::value )); Now that you've done it, is it a good way to solve that problem? Why or why not?
"Is it a good way to solve the problem?" It's not too bad; perhaps boost::mpl::accumulate
would be better as it eliminates the need for the inserter, thus removing a pretty boring pass-through type (replace_with_smaller
), and removing the confusing name, "copy", when we're really doing a iterative traversal and returning a single value.