is_list_constructible_test.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright 2017 Peter Dimov
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt
  6. #if defined( __GNUC__ ) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)
  7. #pragma GCC diagnostic ignored "-Wnarrowing"
  8. #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
  9. #endif
  10. #ifdef TEST_STD
  11. # include <type_traits>
  12. #else
  13. # include <boost/type_traits/is_list_constructible.hpp>
  14. #endif
  15. #include "test.hpp"
  16. #include "check_integral_constant.hpp"
  17. #if defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_DECLTYPE) \
  18. || defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) || defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS)\
  19. || BOOST_WORKAROUND(BOOST_GCC, < 40700)
  20. int main() {}
  21. #else
  22. #include <vector>
  23. struct X
  24. {
  25. int a;
  26. int b;
  27. };
  28. struct Y
  29. {
  30. Y( int = 0, int = 0 );
  31. };
  32. struct Z
  33. {
  34. explicit Z( int = 0, int = 0 );
  35. };
  36. struct V
  37. {
  38. V( int&, int& );
  39. };
  40. TT_TEST_BEGIN(is_list_constructible)
  41. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int>::value), true);
  42. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, int>::value), true);
  43. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, int const>::value), true);
  44. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, int, int>::value), false);
  45. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, char>::value), true);
  46. #if defined(CI_SUPPRESS_KNOWN_ISSUES) && defined(__GNUC__) && (__GNUC__ == 4)
  47. // g++ 4.x doesn't seem to disallow narrowing
  48. #else
  49. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<int, float>::value), false);
  50. #endif
  51. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X>::value), true);
  52. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int>::value), true);
  53. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int const>::value), true);
  54. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int, int>::value), true);
  55. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int const, int const>::value), true);
  56. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int, int, int>::value), false);
  57. #if defined(CI_SUPPRESS_KNOWN_ISSUES) && defined(__GNUC__) && (__GNUC__ == 4)
  58. // g++ 4.x doesn't seem to disallow narrowing
  59. #else
  60. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, float>::value), false);
  61. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<X, int, float>::value), false);
  62. #endif
  63. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y>::value), true);
  64. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int>::value), true);
  65. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int const>::value), true);
  66. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int, int>::value), true);
  67. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int const, int const>::value), true);
  68. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int, int, int>::value), false);
  69. #if defined(CI_SUPPRESS_KNOWN_ISSUES) && defined(__GNUC__) && (__GNUC__ == 4)
  70. // g++ 4.x doesn't seem to disallow narrowing
  71. #elif defined(CI_SUPPRESS_KNOWN_ISSUES) && defined(__GNUC__) && (__GNUC__ == 7) && (__cplusplus >= 201500)
  72. // g++ 7.1 in -std=c++1z, c++17 has a bug
  73. #else
  74. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, float>::value), false);
  75. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Y, int, float>::value), false);
  76. #endif
  77. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z>::value), true);
  78. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int>::value), true);
  79. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int const>::value), true);
  80. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int, int>::value), true);
  81. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int const, int const>::value), true);
  82. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int, int, int>::value), false);
  83. #if defined(CI_SUPPRESS_KNOWN_ISSUES) && defined(__GNUC__) && (__GNUC__ == 4)
  84. // g++ 4.x doesn't seem to disallow narrowing
  85. #elif defined(CI_SUPPRESS_KNOWN_ISSUES) && defined(__GNUC__) && (__GNUC__ == 7) && (__cplusplus >= 201500)
  86. // g++ 7.1 in -std=c++1z, c++17 has a bug
  87. #else
  88. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, float>::value), false);
  89. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<Z, int, float>::value), false);
  90. #endif
  91. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V>::value), false);
  92. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int>::value), false);
  93. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int, int>::value), false);
  94. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int, int, int>::value), false);
  95. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int&, int&>::value), true);
  96. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_list_constructible<V, int const&, int const&>::value), false);
  97. TT_TEST_END
  98. #endif