Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Stl17.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_TEMPLE_STL_17
9 #define INCLUDE_TEMPLE_STL_17
10 
11 #include <type_traits>
12 #include <cassert>
13 #include <functional>
14 
15 namespace Scine {
16 namespace Molassembler {
17 namespace Temple {
18 namespace Stl17 {
19 
20 // From cppreference, possible C++17 clamp implementation
21 template<class T, class Compare>
22 constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp ) {
23  return assert( !comp(hi, lo) ),
24  comp(v, lo) ? lo : comp(hi, v) ? hi : v;
25 }
26 
27 template<class T>
28 constexpr const T& clamp( const T& v, const T& lo, const T& hi ) {
29  return clamp( v, lo, hi, std::less<T>() );
30 }
31 
32 template<class T>
33 constexpr std::add_const_t<T>& as_const(T& t) noexcept {
34  return t;
35 }
36 
37 } // namespace Stl17
38 } // namespace Temple
39 } // namespace Molassembler
40 } // namespace Scine
41 
42 #endif