1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// clang-cl and cl currently don't support [[no_unique_address]]
12// XFAIL: msvc
13
14// [algorithms.results]/1
15// Each of the class templates specified in this subclause has the template parameters,
16// data members, and special members specified below, and has no base classes or members
17// other than those specified.
18
19#include <algorithm>
20
21#include "test_macros.h"
22
23struct Empty {};
24struct Empty2 {};
25
26static_assert(sizeof(std::ranges::in_fun_result<Empty, int>) == sizeof(int));
27static_assert(sizeof(std::ranges::in_fun_result<int, Empty>) == sizeof(int));
28static_assert(sizeof(std::ranges::in_fun_result<Empty, Empty>) == 2);
29
30static_assert(sizeof(std::ranges::in_in_result<Empty, int>) == sizeof(int));
31static_assert(sizeof(std::ranges::in_in_result<int, Empty>) == sizeof(int));
32static_assert(sizeof(std::ranges::in_in_result<Empty, Empty>) == 2);
33
34static_assert(sizeof(std::ranges::in_out_result<Empty, int>) == sizeof(int));
35static_assert(sizeof(std::ranges::in_out_result<int, Empty>) == sizeof(int));
36static_assert(sizeof(std::ranges::in_out_result<Empty, Empty2>) == sizeof(char));
37
38static_assert(sizeof(std::ranges::in_in_out_result<Empty, int, int>) == 2 * sizeof(int));
39static_assert(sizeof(std::ranges::in_in_out_result<int, Empty, int>) == 2 * sizeof(int));
40static_assert(sizeof(std::ranges::in_in_out_result<int, int, Empty>) == 2 * sizeof(int));
41static_assert(sizeof(std::ranges::in_in_out_result<char, Empty, Empty>) == 2);
42static_assert(sizeof(std::ranges::in_in_out_result<Empty, char, Empty>) == 2);
43static_assert(sizeof(std::ranges::in_in_out_result<Empty, Empty, char>) == 2);
44static_assert(sizeof(std::ranges::in_in_out_result<int, Empty, Empty2>) == sizeof(int));
45static_assert(sizeof(std::ranges::in_in_out_result<Empty, Empty, Empty>) == 3);
46
47static_assert(sizeof(std::ranges::in_out_out_result<Empty, int, int>) == 2 * sizeof(int));
48static_assert(sizeof(std::ranges::in_out_out_result<int, Empty, int>) == 2 * sizeof(int));
49static_assert(sizeof(std::ranges::in_out_out_result<int, int, Empty>) == 2 * sizeof(int));
50static_assert(sizeof(std::ranges::in_out_out_result<char, Empty, Empty>) == 2);
51static_assert(sizeof(std::ranges::in_out_out_result<Empty, char, Empty>) == 2);
52static_assert(sizeof(std::ranges::in_out_out_result<Empty, Empty, char>) == 2);
53static_assert(sizeof(std::ranges::in_out_out_result<int, Empty, Empty2>) == sizeof(int));
54static_assert(sizeof(std::ranges::in_out_out_result<Empty, Empty, Empty>) == 3);
55
56#if TEST_STD_VER >= 23
57
58static_assert(sizeof(std::ranges::in_value_result<Empty, int>) == sizeof(int));
59static_assert(sizeof(std::ranges::in_value_result<int, Empty>) == sizeof(int));
60static_assert(sizeof(std::ranges::in_value_result<Empty, Empty2>) == sizeof(Empty2));
61
62#endif // TEST_STD_VER
63
64// In min_max_result both elements have the same type, so they can't have the same address.
65// So the only way to test that [[no_unique_address]] is used is to have it in another struct
66struct MinMaxNoUniqueAddress {
67 int a;
68 TEST_NO_UNIQUE_ADDRESS std::ranges::min_max_result<Empty> b;
69 int c;
70};
71
72static_assert(sizeof(std::ranges::min_max_result<Empty>) == 2);
73static_assert(sizeof(MinMaxNoUniqueAddress) == 8);
74
75static_assert(sizeof(std::ranges::in_found_result<Empty>) == sizeof(bool));
76

source code of libcxx/test/std/algorithms/algorithms.results/no_unique_address.compile.pass.cpp