forked from boostorg/core
Implement data and size functions
This commit is contained in:
46
include/boost/core/data.hpp
Normal file
46
include/boost/core/data.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright 2023 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_CORE_DATA_HPP
|
||||
#define BOOST_CORE_DATA_HPP
|
||||
|
||||
#include <initializer_list>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class C>
|
||||
inline constexpr auto
|
||||
data(C& c) noexcept(noexcept(c.data())) -> decltype(c.data())
|
||||
{
|
||||
return c.data();
|
||||
}
|
||||
|
||||
template<class C>
|
||||
inline constexpr auto
|
||||
data(const C& c) noexcept(noexcept(c.data())) -> decltype(c.data())
|
||||
{
|
||||
return c.data();
|
||||
}
|
||||
|
||||
template<class T, std::size_t N>
|
||||
inline constexpr T*
|
||||
data(T(&a)[N]) noexcept
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline constexpr const T*
|
||||
data(std::initializer_list<T> l) noexcept
|
||||
{
|
||||
return l.begin();
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
31
include/boost/core/size.hpp
Normal file
31
include/boost/core/size.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright 2023 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_CORE_SIZE_HPP
|
||||
#define BOOST_CORE_SIZE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class C>
|
||||
inline constexpr auto
|
||||
size(const C& c) noexcept(noexcept(c.size())) -> decltype(c.size())
|
||||
{
|
||||
return c.size();
|
||||
}
|
||||
|
||||
template<class T, std::size_t N>
|
||||
inline constexpr std::size_t
|
||||
size(T(&)[N]) noexcept
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user