block/include/nil/crypto3/detail/inline_variable.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_INLINE_VARIABLE_HPP
26 #define CRYPTO3_INLINE_VARIABLE_HPP
27 
28 #define CRYPTO3_CXX_STD_14 201402L
29 #define CRYPTO3_CXX_STD_17 201703L
30 
31 #if defined(_MSVC_LANG) && _MSVC_LANG > __cplusplus // Older clangs define _MSVC_LANG < __cplusplus
32 #define CRYPTO3_CXX_VER _MSVC_LANG
33 #else
34 #define CRYPTO3_CXX_VER __cplusplus
35 #endif
36 
37 #ifndef CRYPTO3_CXX17_INLINE_VARIABLES
38 #ifdef __cpp_inline_variables
39 #define CRYPTO3_CXX17_INLINE_VARIABLES __cpp_inline_variables
40 #else
41 #define CRYPTO3_CXX17_INLINE_VARIABLES (CRYPTO3_CXX_VER >= CRYPTO3_CXX_STD_17)
42 #endif
43 #endif
44 
45 #ifdef CRYPTO3_CXX17_INLINE_VARIABLES
46 #define CRYPTO3_INLINE_VARIABLE(TYPE, NAME, VALUE) \
47  constexpr static inline TYPE NAME() { \
48  return TYPE VALUE; \
49  }
50 #else
51 #define CRYPTO3_INLINE_VARIABLE(TYPE, NAME, VALUE) \
52  struct NAME { \
53  inline TYPE const &operator()() const { \
54  static TYPE const v VALUE; \
55  return v; \
56  } \
57  };
58 #endif
59 
60 #endif // CRYPTO3_INLINE_VARIABLE_HPP