-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathstrong_type.hpp
More file actions
41 lines (32 loc) · 867 Bytes
/
strong_type.hpp
File metadata and controls
41 lines (32 loc) · 867 Bytes
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
#pragma once
#include <utility>
namespace rsl {
/** @file */
/**
* @brief Class template for creating strong type aliases
*
* @tparam T value type
* @tparam Tag Tag type to disambiguate separate type aliases
*/
template <typename T, typename Tag>
class StrongType {
T value_;
public:
/**
* @brief Construct from any type
*/
constexpr explicit StrongType(T value) : value_(std::move(value)) {}
/**
* @brief Get non-const reference to underlying value
*/
[[nodiscard]] constexpr T& get() { return value_; }
/**
* @brief Get const reference to underlying value
*/
[[nodiscard]] constexpr T const& get() const { return value_; }
/**
* @brief Explicit conversion to underlying type
*/
[[nodiscard]] constexpr explicit operator T() const { return value_; }
};
} // namespace rsl