Opened 3 years ago

Closed 11 months ago

Last modified 11 months ago

#12092 closed Feature Requests (fixed)

Request: allow std::tuple typelists in BOOST_AUTO_TEST_CASE_TEMPLATE()

Reported by: Tony Lewis <tonyelewis@…> Owned by: Raffi Enficiaud
Milestone: Boost 1.67.0 Component: test
Version: Boost 1.61.0 Severity: Optimization
Keywords: test, tuple, mpl, vector, c++11, typelists Cc:


At present, BOOST_AUTO_TEST_CASE_TEMPLATE requires a Boost MPL sequence type to specify the list of types.

Please may I request that this be extended under >= C++11 compilation to also support a std::tuple<...> type as a way of specifying the types?

I think this would be a good addition because I get the sense that std::tuple is increasingly being preferred as a way to specify typelists (because it's standard, because it allows an arbitrary number of types out-of-the-box and because it doesn't use dummy placeholder types for absent types and so generates much simpler compiler errors).

Under the covers, this could just be implemented by converting to, say an equivalentboost::mpl::vector. This isn't too onerous under modern C++ :

template <typename... Ts>
boost::mpl::vector<Ts...> mpl_vector_of_tuple_impl_fn(const std::tuple<Ts...> &);

template <typename T>
using mpl_vector_of_tuple_t = decltype( mpl_vector_of_tuple_impl_fn( std::declval<T>() ) );

...which can then be used like:

using example_int_char_mpl_vec = mpl_vector_of_tuple_t< std::tuple< int, char > >;

I don't mind if users have to specify a different name (other than BOOST_AUTO_TEST_CASE_TEMPLATE) when using std::tuple.

Thanks very much for your time.

Change History (9)

comment:1 Changed 14 months ago by anonymous

As a heavy user of BOOST unit test I would love to see this idea implemented.

comment:2 Changed 12 months ago by Raffi Enficiaud

Milestone: To Be DeterminedBoost 1.66.0
Owner: changed from Gennadiy Rozental to Raffi Enficiaud
Status: newassigned

comment:3 Changed 12 months ago by Raffi Enficiaud

On branch topic/12092-template-test-case-w-tuples

comment:4 Changed 11 months ago by Raffi Enficiaud

Milestone: Boost 1.66.0Boost 1.67.0

comment:5 Changed 11 months ago by Raffi Enficiaud

On develop

comment:6 Changed 11 months ago by Raffi Enficiaud

Resolution: fixed
Status: assignedclosed

On master

comment:7 Changed 11 months ago by Tony E Lewis <tonyelewis@…>

Thanks very much for this.

As I now understand it, the 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:

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 mpl::vector so that it works from any arbitrary such typelist (including std::tuple) :

template <template <typename...> class U,
          typename... Ts>
boost::mpl::vector<Ts...> mpl_vector_of_typelist_impl_fn(const U<Ts...> &);

template <typename T>
using mpl_vector_of_typelist_t = decltype( mpl_vector_of_typelist_impl_fn( std::declval<T>() ) );

I'm sorry that I didn't suggest this earlier.

comment:8 Changed 11 months ago by Raffi Enficiaud

That is nice! However I closed this ticket, would you please just create a new one?

comment:9 Changed 11 months ago by Tony E Lewis <tonyelewis@…>

Thanks. I've created ticket:13418 for this.

Note: See TracTickets for help on using tickets.