Repository navigation
Expand file tree
/
Copy pathnstd_example.cpp
More file actions
113 lines (90 loc) · 3.3 KB
/
Copy pathnstd_example.cpp
File metadata and controls
113 lines (90 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2018 - 2026 Daniil Goncharov <neargye@gmail.com>.
#include <attributes.hpp>
#include <byte.hpp>
#include <concepts.hpp>
#include <type_traits.hpp>
#include <unused.hpp>
#include <utility.hpp>
#include <type_traits>
#include <string>
#include <iostream>
struct A {};
struct B {
B() = default;
~B() = default;
B(B&&) = default;
B(const B&) = default;
B& operator=(const B&) = default;
B& operator=(B&&) = delete;
};
struct C {
C() = default;
~C() = default;
C(C&&) = default;
C(const C&) = default;
C& operator=(const C&) = delete;
C& operator=(C&&) = default;
};
struct D {
D() = default;
~D() = default;
D(D&&) = default;
D(const D&) = default;
D& operator=(const D&) = default;
D& operator=(D&&) noexcept(false) {
return *this;
}
};
using S = std::string;
template <typename T>
using copy_assign_t = decltype(std::declval<T&>() = std::declval<const T&>());
int main() {
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ > 5) || (defined(_MSC_VER) && _MSC_VER >= 1910)
static_assert(std::is_same<nstd::void_t<>, void>::value, "");
static_assert(nstd::is_detected<copy_assign_t, A>::value, "");
static_assert(!nstd::is_detected<copy_assign_t, C>::value, "");
# if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304L
static_assert(nstd::is_detected_v<copy_assign_t, B>, "");
# endif
#endif
static_assert(std::is_same<nstd::remove_all_ptr<int**>::type, int>::value, "");
int* const* volatile * p;
NSTD_UNUSED(p);
static_assert(std::is_same<nstd::remove_all_ptr_t<decltype(p)>, int>::value, "");
const auto& rp = &p;
NSTD_UNUSED(rp);
static_assert(std::is_same<nstd::remove_all_cv_ref_ptr<decltype(rp)>::type, int>::value, "");
const auto& rp_ = &rp;
NSTD_UNUSED(rp_);
static_assert(std::is_same<nstd::remove_all_cv_ref_ptr_t<decltype(rp_)>, int>::value, "");
const volatile int* const* volatile**** i[10];
NSTD_UNUSED(i);
static_assert(std::is_same<nstd::remove_all_cv_ref_ptr_ext<decltype(i)>::type, int>::value, "");
const auto& ri = &i;
NSTD_UNUSED(ri);
static_assert(std::is_same<nstd::remove_all_cv_ref_ptr_ext_t<decltype(ri)>, int>::value, "");
static_assert(nstd::is_same_signedness<unsigned int, unsigned short>::value, "");
static_assert(!nstd::is_same_signedness<unsigned int, signed short>::value, "");
#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304L
static_assert(nstd::is_same_signedness_v<signed int, signed short>, "");
#endif
A a;
NSTD_UNUSED(a);
static_assert(std::is_same<decltype(nstd::move_assign_if_noexcept(a)), A&&>::value, "");
B b;
NSTD_UNUSED(b);
static_assert(std::is_same<decltype(nstd::move_assign_if_noexcept(b)), const B&>::value, "");
C c;
NSTD_UNUSED(c);
static_assert(std::is_same<decltype(nstd::move_assign_if_noexcept(c)), C&&>::value, "");
D d;
NSTD_UNUSED(d);
static_assert(std::is_same<decltype(nstd::move_assign_if_noexcept(d)), const D&>::value, "");
nstd::invoke_each([](const auto& x) { std::cout << x << " "; }, "invoke_each test", 1, 2, 3);
std::cout << std::endl;
nstd::apply_each([](const auto& x) { std::cout << x << " "; }, std::make_tuple("apply_each test", 1, 2, 3));
std::cout << std::endl;
return 0;
}