Guest User

Untitled

a guest
May 27th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #include <cstddef>
  2. #include <type_traits>
  3. #include <utility>
  4.  
  5.  
  6. //////////////////////////////////////////////////////////////////////////////
  7. // Utilities required to make the bug report self-contained.
  8. //
  9. // Basically, this defines a very minimal tuple<> structure along with a
  10. // function (operator+) which allows appending an element to a tuple. We
  11. // use operator+ because it makes it easier to see what's going on in the
  12. // test cases below.
  13. //////////////////////////////////////////////////////////////////////////////
  14. template <std::size_t i, typename T>
  15. struct element { T storage; };
  16.  
  17. template <typename Indices, typename ...T>
  18. struct tuple_base;
  19.  
  20. template <>
  21. struct tuple_base<std::index_sequence<>> { };
  22.  
  23. template <std::size_t ...i, typename ...T>
  24. struct tuple_base<std::index_sequence<i...>, T...>
  25. : element<i, T>...
  26. {
  27. constexpr tuple_base() = default;
  28. constexpr tuple_base(T const& ...t)
  29. : element<i, T>{t}...
  30. { }
  31. };
  32.  
  33. template <typename ...T>
  34. struct tuple
  35. : tuple_base<std::make_index_sequence<sizeof...(T)>, T...>
  36. {
  37. using Base = tuple_base<std::make_index_sequence<sizeof...(T)>, T...>;
  38. using Base::Base;
  39. };
  40.  
  41. template <std::size_t ...i, typename ...T, typename U>
  42. constexpr tuple<T..., U>
  43. operator+(tuple_base<std::index_sequence<i...>, T...>&& xs, U u) {
  44. return {static_cast<element<i, T>&&>(std::move(xs)).storage..., u};
  45. }
  46.  
  47.  
  48. //////////////////////////////////////////////////////////////////////////////
  49. // Define dumb structures without any "actual" data in it. I know the
  50. // standard still requires them to have a nonzero size, but these are
  51. // still "conceptually" empty in the sense that they are types with a
  52. // single valid value, i.e. the default-constructed one.
  53. //////////////////////////////////////////////////////////////////////////////
  54. struct Empty1 { };
  55. struct Empty { Empty1 e1; Empty1 e2; Empty1 e3; };
  56.  
  57.  
  58. //////////////////////////////////////////////////////////////////////////////
  59. // Define a function which appends 21 "empty" structs to a tuple.
  60. //
  61. // The number 21 is important, since the function is inlined if we only append
  62. // 20 elements to the tuple.
  63. //
  64. // Also, when the function is marked as inline, the problem goes away; the
  65. // function is properly inlined and `main` does not call `f()`.
  66. //////////////////////////////////////////////////////////////////////////////
  67. // inline
  68. auto f() {
  69. return tuple<>{}
  70. + Empty{} + Empty{} + Empty{} + Empty{} + Empty{} + Empty{} + Empty{}
  71. + Empty{} + Empty{} + Empty{} + Empty{} + Empty{} + Empty{} + Empty{}
  72. + Empty{} + Empty{} + Empty{} + Empty{} + Empty{} + Empty{} + Empty{}
  73. ;
  74. }
  75.  
  76. int main() {
  77. f();
  78. }
Add Comment
Please, Sign In to add comment