forked from joboccara/NamedType
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamed_type_impl.hpp
68 lines (55 loc) · 1.74 KB
/
named_type_impl.hpp
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
#ifndef named_type_impl_h
#define named_type_impl_h
#include <type_traits>
#include <utility>
// Enable empty base class optimization with multiple inheritance on Visual Studio.
#if defined(_MSC_VER) && _MSC_VER >= 1910
# define FLUENT_EBCO __declspec(empty_bases)
#else
# define FLUENT_EBCO
#endif
namespace fluent
{
template<typename T>
using IsNotReference = typename std::enable_if<!std::is_reference<T>::value, void>::type;
template <typename T, typename Parameter, template<typename> class... Skills>
class FLUENT_EBCO NamedType : public Skills<NamedType<T, Parameter, Skills...>>...
{
public:
using UnderlyingType = T;
// constructor
explicit constexpr NamedType(T const& value) : value_(value) {}
template<typename T_ = T, typename = IsNotReference<T_>>
explicit constexpr NamedType(T&& value) : value_(std::move(value)) {}
// get
constexpr T& get() { return value_; }
constexpr std::remove_reference_t<T> const& get() const {return value_; }
// conversions
using ref = NamedType<T&, Parameter, Skills...>;
operator ref ()
{
return ref(value_);
}
struct argument
{
template<typename U>
NamedType operator=(U&& value) const
{
return NamedType(std::forward<U>(value));
}
argument() = default;
argument(argument const&) = delete;
argument(argument &&) = delete;
argument& operator=(argument const&) = delete;
argument& operator=(argument &&) = delete;
};
private:
T value_;
};
template<template<typename T> class StrongType, typename T>
constexpr StrongType<T> make_named(T const& value)
{
return StrongType<T>(value);
}
} // namespace fluent
#endif /* named_type_impl_h */