2

When specifying the parameter packs for a type, I want to be able to accept not only typenames but also values of arbitrary types. Example:

template <thing... Things>
//        ^^^^^   <- pseudo code
struct Example {};

Example<int,bool>();
Example<4,float,'x'>();

Clearly, thing is not a valid C++ keyword, but is the idea expressed here at all possible?


The context for this is that I have a container adapter that wants to insert its own value type into the container but allow to pass any additional template parameters, and some containers receive not just type arguments but also values (std::array would be a popular example).

template <template <typename...> typename Container, typename... Args>
struct Adapter {
  struct Node { /* ... */ };
  Container<Node,Args...> container;
};

Adapter<std::vector>(); // fine
Adapter<std::vector,MyAllocator>(); // fine
Adapter<std::array,3>(); // nope because 3 is not a typename
bitmask
  • 32,434
  • 14
  • 99
  • 159
  • 2
    Not possible, at the moment (C++17 but also C++20, as far I know). The best I can suggest is wrap values inside a class (by example: not `3` but `std::integral_constant`). – max66 Aug 20 '20 at 18:44
  • @max66 Yes, my thinking was also going to something like `integral_constant`, but that would require the underlying types to accept this, which (for example) `std::array` does not. And there couldn't even be an overload for the same reason. – bitmask Aug 20 '20 at 18:46
  • Assuming you know the possible values passed, can't you just use a `void *` and then try reading it as all possible values to find valid ones? Otherwise try [this](https://stackoverflow.com/questions/1718412/find-out-type-of-c-void-pointer) – Sarwagya Aug 20 '20 at 18:56

0 Answers0