Opened 8 years ago

#10027 new Feature Requests

Allow template parameters with types rather than hardcode typename in BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE (and friends)

Reported by: Jonas Lippuner <jonas@…> Owned by: Joel de Guzman
Milestone: To Be Determined Component: fusion
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

Right now, the macro BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE creates

template<typename A, typename B>
struct MyStruct { ... };

from

BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE(
  (A)(B),
  MyStruct,
  (A, foo)
  (B, bar)
)

But I want to put the class template<int DIM> class Vector into a Boost Fusion Struct. So the struct should allow template parameters that are not typenames. I would like to be able to write the following:

BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE(
  (int DIM)(typename B),
  MyStruct,
  (Vector<DIM>, foo)
  (B, bar)
)

// the above becomes
// template<int DIM, typename B>
// struct MyStruct { ... };

MyStruct<3, double> struct;

This does not currently work. The following is a working (but cumbersome) workaround (using C++11):

BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE(
  (DIM)(B),
  MyStructImpl,
  (Vector<DIM::value>, foo)
  (B, bar)
)

template<int DIM>
using MyStruct = MyStructImpl<boost::mpl::int_<DIM>>;

MyStruct<3, double> struct;

Maybe for backwards compatibility my proposed version of BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE where template parameters are declared as (int DIM)(typename B) should be named BOOST_FUSION_DEFINE_FLEXIBLE_TPL_STRUCT_INLINE.

Change History (0)

Note: See TracTickets for help on using tickets.