extent: make area and diameter constexpr
This commit is contained in:
parent
657a407d0e
commit
66f0bbc025
28
extent.cpp
28
extent.cpp
@ -42,34 +42,6 @@ extent<S,T>::extent (vector<S,T> _v)
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
T
|
||||
extent<S,T>::diameter (void) const
|
||||
{
|
||||
return static_cast<T> (
|
||||
std::sqrt (
|
||||
std::accumulate (std::begin (this->data),
|
||||
std::end (this->data),
|
||||
T {0},
|
||||
[] (auto a, auto b) { return a + b * b; })
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
T
|
||||
extent<S,T>::area (void) const
|
||||
{
|
||||
return std::accumulate (std::begin (this->data),
|
||||
std::end (this->data),
|
||||
T {1},
|
||||
std::multiplies<T> ());
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
extent<S,T>
|
||||
|
@ -34,10 +34,11 @@ namespace util {
|
||||
extent () = default;
|
||||
explicit extent (vector<S,T>);
|
||||
|
||||
T area (void) const;
|
||||
T diameter (void) const;
|
||||
constexpr T area (void) const;
|
||||
constexpr T diameter (void) const;
|
||||
|
||||
template <typename U = float>
|
||||
constexpr
|
||||
U aspect (void) const;
|
||||
|
||||
template <typename U>
|
||||
|
31
extent.ipp
31
extent.ipp
@ -24,9 +24,40 @@
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
constexpr
|
||||
T
|
||||
util::extent<S,T>::diameter (void) const
|
||||
{
|
||||
return static_cast<T> (
|
||||
std::sqrt (
|
||||
std::accumulate (std::begin (this->data),
|
||||
std::end (this->data),
|
||||
T {0},
|
||||
[] (auto a, auto b) { return a + b * b; })
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
constexpr
|
||||
T
|
||||
util::extent<S,T>::area (void) const
|
||||
{
|
||||
return std::accumulate (std::begin (this->data),
|
||||
std::end (this->data),
|
||||
T {1},
|
||||
std::multiplies<T> ());
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
template <typename U>
|
||||
constexpr
|
||||
U
|
||||
util::extent<S,T>::aspect (void) const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user