0

Recently I have stumbled across user defined literals, especially the templated variadic char array kinds:

template<char... chars>
constexpr size_t operator""_size(){
  return sizeof...(chars);
}

//Later
constexpr size_t size = "this is text"_size;

Is there any way to do this with a normal constexpr function?

Something like this:

template<char... chars>
constexpr size_t size(){
  return sizeof...(chars);
}

//Later
constexpr size_t size = size("this is text");

This would allow multiple parameters and regular syntax.

So is there any way to do do the templated variadic char array as a parameter trick to normal functions (or some way to achieve a similar effect)?

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
DarthRubik
  • 3,927
  • 1
  • 18
  • 54

0 Answers0