3

Let's say I have a template structure:

template<typename... Args>
struct Foo {
    static_assert(/*code*/);
    //to do
}

I want to check in static_assert if types in Args are all different types. I know how to do it using additional template structures and template specialization. Maybe there exists a one-line solution for this problem? I can use C++17

The linked question was asked 2 years ago and maybe there is a shorter solution which uses for example multiple pack expansion somehow.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
wisniak
  • 163
  • 7
  • when you do std::get in you for_each loop ( that you have to create ) you should get compile time error if there is a duplicate. Would that do? – g24l Dec 08 '15 at 14:56
  • std::get should be applied in a tuple made from the arguments . – g24l Dec 08 '15 at 15:04
  • 2
    @g24l: something like that [Demo](http://coliru.stacked-crooked.com/a/bf7f114488c75f16). – Jarod42 Dec 08 '15 at 15:09
  • [Here](http://coliru.stacked-crooked.com/a/d29f503a45aa9892)'s a possible solution using `std::experimental::disjunction` and friends. – TartanLlama Dec 08 '15 at 15:14
  • @Jarod42 , yes exactly what I meant. It's a same this was marked duplicate, I don't see how it is answered in the linked post. whatever, moving on. – g24l Dec 08 '15 at 15:15
  • @101010 those are all C++11 solutions in that question. Admittedly when you closed it the OP did not mention C++17, but there was C++14. ;) Reopening, as C++14/C++17 does admit much improved solutions. – Yakk - Adam Nevraumont Dec 08 '15 at 16:26
  • 2
    C++14 > SOLUTIONS: http://stackoverflow.com/questions/34025327/how-can-i-make-this-variadic-template-code-shorter-using-features-from-c14-and – 101010 Dec 08 '15 at 16:30
  • @101010 Awesome, reclosed with that one! – Yakk - Adam Nevraumont Dec 08 '15 at 17:03

0 Answers0