Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Struct.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Struct.hpp"
18
19#include <boost/test/unit_test.hpp>
20
21using namespace std;
22using namespace toolbox;
23
24namespace {
25namespace tag {
26struct Foo {};
27struct Bar {};
28} // namespace tag
29
30static_assert(empty(Struct));
31static_assert(!empty(Struct.extend<tag::Foo>(101)));
32static_assert(size(Struct.extend<tag::Foo>(101)) == 1);
33static_assert(has<tag::Foo>(Struct.extend<tag::Foo>(101)));
34static_assert(!has<tag::Bar>(Struct.extend<tag::Foo>(101)));
35static_assert(get<tag::Foo>(Struct.extend<tag::Foo>(101)) == 101);
36
37} // namespace
38
40
49
51{
52 struct Test {
53 int x;
54 };
55
56 const auto s = Struct.extend<tag::Foo>(Test{101});
62}
63
65{
66 struct Test {
67 int x;
68 };
69
70 const auto s = Struct.extend<tag::Foo>(Test{101}).extend<tag::Bar>(Test{202});
77}
78
80{
81 const auto s = Struct.extend<tag::Foo>([](int x) { return x + x; });
83}
84
86{
87 auto s = Struct.extend<tag::Foo>(101);
89 get<tag::Foo>(s) = 202;
91}
92
BOOST_CHECK_EQUAL(v.size(), 10U)
BOOST_AUTO_TEST_CASE(StructEmptyCase)
Definition Struct.ut.cpp:41
STL namespace.
constexpr auto Struct
Definition Struct.hpp:89
constexpr std::size_t size(const detail::Struct< detail::Member< TagsT, ValuesT >... > &s)
Definition Struct.hpp:98
constexpr bool empty(const detail::Struct< detail::Member< TagsT, ValuesT >... > &s)
Definition Struct.hpp:92
constexpr auto bind() noexcept
Definition Slot.hpp:92
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))