Nano
A C++ template metaprogramming library
numeric_types.hpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------------------------------------
2 /// @file numeric_types.hpp
3 /// @brief Header file for static numeric types to use for meta functions
4 // ----------------------------------------------------------------------------------------------------------
5 
6 /*
7  * ----------------------------------------------------------------------------------------------------------
8  * Numeric types header file for nano library.
9  * Copyright (C) 2015 Rob Clucas
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  * ----------------------------------------------------------------------------------------------------------
25  */
26 
27 #ifndef NANO_NUMERIC_TYPES_HPP
28 #define NANO_NUMERIC_TYPES_HPP
29 
30 #include <cstdlib>
31 
32 namespace nano {
33 
34 // ----------------------------------------------------------------------------------------------------------
35 /// @struct size_t
36 /// @brief Wrapper around size_t for static size_t types used by metaclass and metafunctions in nano
37 /// @tparam Value The value of the size_t type
38 // ----------------------------------------------------------------------------------------------------------
39 template <std::size_t Value>
40 struct size_t
41 {
42  // Define the type of Value
43  using type = std::size_t;
44 
45  // ------------------------------------------------------------------------------------------------------
46  /// @brief Gets the value of the tyoe at compile time
47  // ------------------------------------------------------------------------------------------------------
48  static constexpr std::size_t value = Value;
49 
50  // -------------------------------------------------------------------------------------------------------
51  /// @brief Gets the value of the type at runtime
52  /// @return The value the type is holding
53  // -------------------------------------------------------------------------------------------------------
54  constexpr std::size_t runtime_value() const { return Value; }
55 };
56 
57 // ----------------------------------------------------------------------------------------------------------
58 /// @struct int_t
59 /// @brief Wrapper around int for static int types used by metaclass and metafunctions in nano
60 /// @tparam Value The value of the int type
61 // ----------------------------------------------------------------------------------------------------------
62 template <int Value>
63 struct int_t
64 {
65  // Define the type of Value
66  using type = int;
67 
68  // ------------------------------------------------------------------------------------------------------
69  /// @brief Gets the value type at compile time
70  // ------------------------------------------------------------------------------------------------------
71  static constexpr int value = Value;
72 
73  // -------------------------------------------------------------------------------------------------------
74  /// @brief Gets the value of the type at runtime
75  /// @return The value the type is holding
76  // -------------------------------------------------------------------------------------------------------
77  constexpr int runtime_value() const { return Value; }
78 };
79 
80 } // End namespace nano
81 
82 #endif // NANO_NUMERIC_TYPES_HPP
Wrapper around int for static int types used by metaclass and metafunctions in nano.
Definition: numeric_types.hpp:63
std::size_t type
Definition: numeric_types.hpp:43
Definition: containers.hpp:34
static constexpr std::size_t value
Gets the value of the tyoe at compile time.
Definition: numeric_types.hpp:48
constexpr std::size_t runtime_value() const
Gets the value of the type at runtime.
Definition: numeric_types.hpp:54
int type
Definition: numeric_types.hpp:66
static constexpr int value
Gets the value type at compile time.
Definition: numeric_types.hpp:71
Wrapper around size_t for static size_t types used by metaclass and metafunctions in nano...
Definition: numeric_types.hpp:40
constexpr int runtime_value() const
Gets the value of the type at runtime.
Definition: numeric_types.hpp:77