add_varargs.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*<-
  2. Copyright Barrett Adair 2016-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt)
  5. ->*/
  6. //[ add_varargs
  7. #include <type_traits>
  8. #include <boost/callable_traits/add_varargs.hpp>
  9. namespace ct = boost::callable_traits;
  10. struct foo {};
  11. int main() {
  12. {
  13. using f = void(int);
  14. using expect = void(int, ...);
  15. using test = ct::add_varargs_t<f>;
  16. static_assert(std::is_same<test, expect>::value, "");
  17. } {
  18. using fp = void(*)();
  19. using expect = void(*)(...);
  20. using test = ct::add_varargs_t<fp>;
  21. static_assert(std::is_same<test, expect>::value, "");
  22. } {
  23. using fr = void(&)(const char*);
  24. using expect = void(&)(const char*, ...);
  25. using test = ct::add_varargs_t<fr>;
  26. static_assert(std::is_same<test, expect>::value, "");
  27. } {
  28. using pmf = void(foo::*)() const;
  29. using expect = void(foo::*)(...) const;
  30. using test = ct::add_varargs_t<pmf>;
  31. static_assert(std::is_same<test, expect>::value, "");
  32. // add_varargs_t doesn't change anything when
  33. // the type already has varargs.
  34. using twice = ct::add_varargs_t<test>;
  35. static_assert(std::is_same<test, twice>::value, "");
  36. }
  37. }
  38. //]