coord/ops: move `get' query to top for usage later

This commit is contained in:
Danny Robson 2018-03-13 14:33:51 +11:00
parent f4465329c8
commit 16c6a6d627

View File

@ -33,8 +33,56 @@
#include <cstdlib> #include <cstdlib>
#include <iterator> #include <iterator>
#include <functional> #include <functional>
#include <argon2.h>
namespace util { namespace util {
/// returns the data at a templated index in a coordinate.
///
/// specifically required for structured bindings support.
///
/// \tparam I index of the requested data
/// \tparam S dimensionality of the coordinate
/// \tparam T underlying data type of the coordinate
/// \tparam K coordinate data type to operate on
template <
std::size_t I,
typename K,
typename = std::enable_if_t<
is_coord_v<K>, void
>
>
const auto&
get (const K &k)
{
static_assert (I < K::elements);
return k[I];
};
/// returns the data at a templated index in a coordinate.
///
/// specifically required for structured bindings support.
///
/// \tparam I index of the requested data
/// \tparam S dimensionality of the coordinate
/// \tparam T underlying data type of the coordinate
/// \tparam K coordinate data type to operate on
template <
std::size_t I,
typename K,
typename = std::enable_if_t<
is_coord_v<K> && I < K::elements, void
>
>
auto &
get (K &k)
{
static_assert (I < K::elements);
return k[I];
};
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// a templated functor that exposes arithmetic and assignment maths // a templated functor that exposes arithmetic and assignment maths
// functions for vector-vector or vector-scalar operations. // functions for vector-vector or vector-scalar operations.
@ -1276,52 +1324,6 @@ namespace util {
{ {
return rshift (k, num, K {fill}); return rshift (k, num, K {fill});
} }
/// returns the data at a templated index in a coordinate.
///
/// specifically required for structured bindings support.
///
/// \tparam I index of the requested data
/// \tparam S dimensionality of the coordinate
/// \tparam T underlying data type of the coordinate
/// \tparam K coordinate data type to operate on
template <
std::size_t I,
typename K,
std::enable_if_t<
is_coord_v<K> && I < K::elements, void
>
>
const auto&
get (const K &k)
{
static_assert (I < K::elements);
return k[I];
};
/// returns the data at a templated index in a coordinate.
///
/// specifically required for structured bindings support.
///
/// \tparam I index of the requested data
/// \tparam S dimensionality of the coordinate
/// \tparam T underlying data type of the coordinate
/// \tparam K coordinate data type to operate on
template <
std::size_t I,
typename K,
typename = std::enable_if_t<
is_coord_v<K> && I < K::elements, void
>
>
auto &
get (K &k)
{
static_assert (I < K::elements);
return k[I];
};
} }