M5Utility 0.0.12 git rev:13bfbd6
Loading...
Searching...
No Matches
extension.hpp File Reference

STL extensions. More...

#include <algorithm>
#include <cstddef>
#include <type_traits>

Go to the source code of this file.

Namespaces

namespace  m5
 Top level namespace of M5.
 

Functions

template<class C >
constexpr auto m5::stl::size (const C &c) -> decltype(c.size())
 Like std::size C++17 or later.(for container)
 
template<typename T , size_t N>
constexpr auto m5::stl::size (const T(&)[N]) noexcept -> size_t
 Like std::size C++17 or later.(for raw array)
 
template<class T >
constexpr const T & m5::stl::clamp (const T &v, const T &low, const T &high)
 Like std::clamp C++17 or later.
 
template<class T , class Compare >
constexpr const T & m5::stl::clamp (const T &v, const T &low, const T &high, Compare comp)
 
template<typename E >
constexpr std::underlying_type< E >::type m5::stl::to_underlying (const E e) noexcept
 Converts an enumeration to its underlying type.(Like std::to_underlying C++23 or later)
 

Detailed Description

STL extensions.

Add features that cannot be used depending on the C++ version, etc.

SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD

SPDX-License-Identifier: MIT

Function Documentation

◆ clamp()

template<class T >
const T & m5::stl::clamp ( const T & v,
const T & low,
const T & high )
constexpr

Like std::clamp C++17 or later.

Template Parameters
TType
Parameters
vValue to clamp
lowLower bound
highUpper bound
Returns
Reference to low, high, or v

◆ to_underlying()

template<typename E >
std::underlying_type< E >::type m5::stl::to_underlying ( const E e)
inlineconstexprnoexcept

Converts an enumeration to its underlying type.(Like std::to_underlying C++23 or later)

Template Parameters
EType of enum
Parameters
eEnumeration value to convert
Returns
The integer value of the underlying type of Enum, converted from e.