RESTinio
Loading...
Searching...
No Matches
tagged_scalar.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
5/*!
6 * @file
7 * @brief Helper template for defining tagged scalar types.
8 *
9 * @since v.0.6.12
10 */
11
12#pragma once
13
14#include <restinio/compiler_features.hpp>
15
16#include <type_traits>
17
18namespace restinio
19{
20
21namespace utils
22{
23
24//
25// tagged_scalar_t
26//
27/*!
28 * @brief Helper template for defining tagged scalar types.
29 *
30 * Usage example:
31 * @code
32 * struct max_parallel_connections_tag {};
33 * using max_parallel_connections_t = tagged_scalar_t<
34 * std::size_t, max_parallel_connections_tag >;
35 *
36 * struct max_active_accepts_tag {};
37 * using max_active_accepts_t = tagged_scalar_t<
38 * std::size_t, max_active_accepts_tag >;
39 *
40 * class limiter_t
41 * {
42 * public:
43 * limiter_t(
44 * max_parallel_connections_t parallel_connections,
45 * max_active_accepts_t active_accepts);
46 * ...
47 * };
48 * @endcode
49 *
50 * @since v.0.6.12
51 */
52template< typename Scalar, typename Tag >
54{
55 static_assert( std::is_scalar<Scalar>::value,
56 "Scalar is expected to be scalar type" );
57
58 Scalar m_value;
59
60public:
61 constexpr explicit tagged_scalar_t( Scalar value ) noexcept
62 : m_value{ value }
63 {}
64
65 [[nodiscard]]
66 constexpr Scalar
67 value() const noexcept { return m_value; }
68};
69
70} /* namespace utils */
71
72} /* namespace restinio */
Helper template for defining tagged scalar types.
constexpr tagged_scalar_t(Scalar value) noexcept
constexpr Scalar value() const noexcept