Closes #18 Co-authored-by: Jules Pénuchot <jules@penuchot.com> See merge request oss/rotgen!50
87 lines
3.1 KiB
C++
87 lines
3.1 KiB
C++
//==============================================================================
|
|
/*
|
|
ROTGEN - Runtime Overlay for Eigen
|
|
Copyright : CODE RECKONS
|
|
SPDX-License-Identifier: BSL-1.0
|
|
*/
|
|
//==============================================================================
|
|
#pragma once
|
|
|
|
#include <rotgen/config.hpp>
|
|
|
|
#include <type_traits>
|
|
|
|
#define ROTGEN_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
|
|
|
|
namespace rotgen::detail
|
|
{
|
|
/// Returned when a function is called with unsupported parameters,
|
|
/// effectively triggering a compile error to avoid undefined behaviors in
|
|
/// cases where return directives are missing.
|
|
template<typename T> auto unsupported_parameters()
|
|
{
|
|
static_assert(sizeof(T) == 0,
|
|
"Function was called with unsupported parameters.");
|
|
};
|
|
|
|
template<typename T> constexpr int static_size()
|
|
{
|
|
auto rows = T::RowsAtCompileTime;
|
|
auto cols = T::ColsAtCompileTime;
|
|
if (rows == 0 || cols == 0) return 0;
|
|
if (rows == -1 || cols == -1) return -1;
|
|
return rows * cols;
|
|
}
|
|
|
|
template<typename EigenType,
|
|
template<typename, int, int, int, int, int> typename Wrapper>
|
|
struct as_concrete
|
|
{
|
|
using type = Wrapper<typename EigenType::value_type,
|
|
EigenType::RowsAtCompileTime,
|
|
EigenType::ColsAtCompileTime,
|
|
EigenType::IsRowMajor ? RowMajor : ColMajor,
|
|
EigenType::MaxRowsAtCompileTime,
|
|
EigenType::MaxColsAtCompileTime>;
|
|
};
|
|
|
|
template<typename EigenType,
|
|
template<typename, int, int, int, int, int> typename Wrapper>
|
|
using as_concrete_t =
|
|
typename as_concrete<std::remove_cvref_t<EigenType>, Wrapper>::type;
|
|
|
|
template<template<typename, int, int, int, int, int> typename Wrapper>
|
|
decltype(auto) concretize(auto const& t)
|
|
{
|
|
if constexpr (use_expression_templates) return t;
|
|
else return as_concrete_t<std::remove_cvref_t<decltype(t)>, Wrapper>(t);
|
|
}
|
|
|
|
template<typename M, typename N>
|
|
inline constexpr bool has_same_vector_size = []() {
|
|
// No vector = noo size
|
|
if (!(M::IsVectorAtCompileTime && N::IsVectorAtCompileTime)) return false;
|
|
else return static_size<M>() == static_size<N>();
|
|
}();
|
|
|
|
template<typename T>
|
|
using propagate_const =
|
|
std::conditional_t<std::remove_cvref_t<T>::is_immutable ||
|
|
std::is_const_v<T>,
|
|
std::add_const_t<std::remove_cvref_t<T>>,
|
|
std::remove_reference_t<T>>;
|
|
|
|
template<auto M, auto N>
|
|
inline constexpr auto select_static = (M == -1 || N == -1) ? -1 : M;
|
|
|
|
template<typename M1,
|
|
typename M2,
|
|
template<typename, int, int, int, int, int> typename Wrapper>
|
|
using composite_type =
|
|
Wrapper<typename M1::value_type,
|
|
select_static<M1::RowsAtCompileTime, M2::RowsAtCompileTime>,
|
|
select_static<M1::ColsAtCompileTime, M2::ColsAtCompileTime>,
|
|
M1::storage_order,
|
|
select_static<M1::MaxRowsAtCompileTime, M2::MaxRowsAtCompileTime>,
|
|
select_static<M1::MaxColsAtCompileTime, M2::MaxColsAtCompileTime>>;
|
|
}
|