Subject: [Boost-bugs] [Boost C++ Libraries] #13418: Request: allow general typelist types in BOOST_AUTO_TEST_CASE_TEMPLATE()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-01-24 12:28:54
#13418: Request: allow general typelist types in BOOST_AUTO_TEST_CASE_TEMPLATE()
-------------------------------------------------+-------------------------
Reporter: Tony E Lewis <tonyelewis@â¦> | Owner: Gennadiy
| Rozental
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: test
Version: Boost 1.66.0 | Severity:
Keywords: | Optimization
mpl,test,typelist,template,c++11,tuple,tmp,metaprogramming|
-------------------------------------------------+-------------------------
In ticket:12092 I requested that `BOOST_AUTO_TEST_CASE_TEMPLATE()` be
generalised to allow users to specify the typelist as a `std::tuple` of
types, as well as a `boost::mpl::vector`. You added this feature - thanks
very much.
As discussed in ticket:12092#comment:7, since I made the original request,
I've come to realise that TMP gurus avoid using `std::tuple` as a typelist
because it has complex guts that needlessly eat up compiler-time for each
instantiation. Instead, I think they typically just use an arbitrary empty
template struct, eg:
{{{
#!cpp
template <typename...> struct my_typelist_wrapper {};
using a_typelist = my_typelist_wrapper<int, char>;
}}}
With this in mind, it might be nice to consider finessing the conversion
to `boost::mpl::vector` so that it works from any arbitrary such typelist
(including `std::tuple`). Here's an illustrative implementation of the
idea (which I've slightly tweaked since ticket:12092#comment:7 so that if
the metafunction is called with anything other than a single, valid
typelist, it will return a dummy type with a descriptive name which will
hopefully make the compiler errors more helpful):
{{{
#!cpp
struct arg_type_is_not_single_valid_typelist final {
arg_type_is_not_single_valid_typelist() = delete;
~arg_type_is_not_single_valid_typelist() = delete;
arg_type_is_not_single_valid_typelist(const
arg_type_is_not_single_valid_typelist &) = delete;
arg_type_is_not_single_valid_typelist & operator=(const
arg_type_is_not_single_valid_typelist &) = delete;
};
template <typename...>
struct mpl_vector_of_typelist_impl {
using type = arg_type_is_not_single_valid_typelist;
};
template <template <typename...> class T,
typename... Us>
struct mpl_vector_of_typelist_impl< T< Us... > > {
using type = boost::mpl::vector<Us...>;
};
template <typename T>
using mpl_vector_of_typelist_t = typename
mpl_vector_of_typelist_impl<T>::type;
}}}
Here are some simple usage examples:
{{{
#!cpp
template <typename...> struct my_typelist_wrapper {};
static_assert( std::is_same< mpl_vector_of_typelist_t<
my_typelist_wrapper< int, char > >, boost::mpl::vector<int, char >
>::value, "" );
static_assert( std::is_same< mpl_vector_of_typelist_t< std::tuple
< int, char > >, boost::mpl::vector<int, char > >::value, "" );
static_assert( std::is_same< mpl_vector_of_typelist_t< int
>, arg_type_is_not_single_valid_typelist >::value, "" );
}}}
-- Ticket URL: <https://svn.boost.org/trac10/ticket/13418> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2018-01-24 12:34:24 UTC