openMSX
semiregular_test.cc
Go to the documentation of this file.
1#include "catch.hpp"
2#include "semiregular.hh"
3#include <memory>
4
5
6// Mockup for an transform-iterator containing a transformation function (e.g.
7// a lambda).
8template<typename Op> struct Iter {
9 Iter() = default;
10 explicit Iter(Op op_) : op(std::move(op_)) {}
11 semiregular_t<Op> op; // wrap 'Op' in semiregular_t<T>
12};
13
14TEST_CASE("semiregular")
15{
16 // This doesn't CHECK() anything, it only tests that the code compiles.
17 SECTION("semiregular_t<lambda>") {
18 int g = 42;
19
20 // create dummy lambda, captures 'g' by-reference.
21 auto lambda = [&](int i) { return i + g; };
22 auto l2 = lambda; (void)l2; // lambda is copy-constructible
23 // l2 = lambda; // ok, doesn't compile: lambda is not copy-assignable
24 // decltype(lambda) l3; // ok, doesn't compile: not default-constructible
25
26 // create iterator containing this lambda
27 auto iter1 = Iter(std::move(lambda));
28 auto iter2 = iter1; // ok, copy-constructible
29 iter2 = iter1; // ok, copy-assignable
30 decltype(iter1) iter3; // ok, default-constructible
31 (void)iter2; (void)iter3;
32 }
33 SECTION("semiregular_t<unique_ptr<int>>") {
34 // unique_ptr
35 using T = std::unique_ptr<int>;
36 auto t1 = std::make_unique<int>(43);
37 // T t2 = t1; // ok, doesn't compile: move-only
38
39 // wrapped in semiregular_t<T>
40 using ST = semiregular_t<T>;
41 ST st1 = std::move(t1);
42 // ST st2 = st1; ok, doesn't compile because move-only
43 ST st2 = std::move(st1);
44 st1 = std::move(st2);
45 }
46}
int g
STL namespace.
std::conditional_t< std::is_default_constructible_v< T > &&std::is_copy_assignable_v< T >, T, sreg_impl::semiregular< T > > semiregular_t
TEST_CASE("semiregular")
Iter()=default
semiregular_t< Op > op
Iter(Op op_)