Convert Tuple Type

So, I'm new to MPL augmentation and I don't know how to use it with standard types.

I want a metafunct that hides this type:

std::tuple<T0, T1, ..., TN>

      

In it:

std::tuple<
  std::function<T0(std::tuple<T0, T1, ...>, std::tuple<T0, T1, ...>)>,
  std::function<T1(std::tuple<T0, T1, ...>, std::tuple<T0, T1, ...>)>,
  ...,
  std::function<TN(...)>
>

      

and it seems like it can be done with transform , but I want to have a tuple type, not a type vector. (You don't really need to use MPL, but I think it would be shorter?)

Background: I am currently using completely generic types and relying on all hell to break if used incorrectly, but I want to calculate TupleOfFunctions

to get the correct error.

template<class TupleOfValues, class TupleOfFunctions>
void f(TupleOfValues v, TupleOfFunctions fun)

      

+2


source to share


1 answer


How about the next one?



template<typename T> struct transform;
template<typename ...T>
struct transform<std::tuple<T...>> {
  typedef std::tuple<std::function<T(std::tuple<T...>, std::tuple<T...>)>...> type;
};

      

+4


source







All Articles