|
6 | 6 | #include <type_traits>
|
7 | 7 | #include <utility>
|
8 | 8 |
|
| 9 | +#if (__has_cpp_attribute(no_unique_address)) |
| 10 | +#define TUPLET_NO_UNIQUE_ADDRESS [[no_unique_address]] |
| 11 | +#elif (__has_cpp_attribute(msvc::no_unique_address)) \ |
| 12 | + || ((defined _MSC_VER) && (!defined __clang__)) |
| 13 | +// Note __has_cpp_attribute(msvc::no_unique_address) itself doesn't work as |
| 14 | +// of 19.30.30709, even though the attribute itself is supported. See |
| 15 | +// https://github.com/llvm/llvm-project/issues/49358#issuecomment-981041089 |
| 16 | +#define TUPLET_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] |
| 17 | +#else |
| 18 | +// no_unique_address is not available. |
| 19 | +#define TUPLET_NO_UNIQUE_ADDRESS |
| 20 | +#endif |
| 21 | + |
9 | 22 | // tuplet concepts and traits
|
10 | 23 | namespace tuplet {
|
11 | 24 | template <class T>
|
@@ -94,7 +107,7 @@ struct tuple_elem {
|
94 | 107 | static T decl_elem(tag<I>);
|
95 | 108 | using type = T;
|
96 | 109 |
|
97 |
| - [[no_unique_address]] T value; |
| 110 | + TUPLET_NO_UNIQUE_ADDRESS T value; |
98 | 111 |
|
99 | 112 | constexpr decltype(auto) operator[](tag<I>) & { return (value); }
|
100 | 113 | constexpr decltype(auto) operator[](tag<I>) const& { return (value); }
|
@@ -242,8 +255,8 @@ namespace tuplet {
|
242 | 255 | template <class First, class Second>
|
243 | 256 | struct pair {
|
244 | 257 | constexpr static size_t N = 2;
|
245 |
| - [[no_unique_address]] First first; |
246 |
| - [[no_unique_address]] Second second; |
| 258 | + TUPLET_NO_UNIQUE_ADDRESS First first; |
| 259 | + TUPLET_NO_UNIQUE_ADDRESS Second second; |
247 | 260 |
|
248 | 261 | constexpr decltype(auto) operator[](tag<0>) & { return (first); }
|
249 | 262 | constexpr decltype(auto) operator[](tag<0>) const& { return (first); }
|
|
0 commit comments