Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 2c912274 authored by Quentin Khan's avatar Quentin Khan
Browse files

FBasicParticle: static_assert variadic constructor argument length

The variadic constructor stores the attributes passed as parameters. The
error was not clear when too many attributes were passed.
parent 867b7c14
......@@ -18,6 +18,22 @@ public:
using types_tuple_t = scalfmm::
pack_expand_tuple< Types... >;
/// Expand std::enable_if if possible
template<bool value>
using sfinae_check = typename std::enable_if<value, bool>::type;
/**
* \brief Check parameter pack size vs. attribute + dimension count at
* compile time
*
* \return true if the parameter pack is shorter than the attribute list
* size + the dimension
*/
template<typename... Ts>
constexpr static bool correct_size() {
return std::tuple_size<data_t>::value >= sizeof...(Ts) + Dim;
}
/// Space dimensions
constexpr static std::size_t Dim = _Dim;
/// Size of #data_t tuple
......@@ -41,8 +57,19 @@ public:
/// Default move operator
FBasicParticle& operator=(FBasicParticle&&) = default;
/// Constructor from position and types
template<typename... Ts>
/**
* \brief Constructor from position and types
*
* \tparam Ts Attributes parameter pack
*
* \param pos Particle position
* \param ts Attributes
*
* \warning There may be less attributes than defined by the particle, in
* that case the missing ones are zero constructed.
*/
template<typename... Ts,
sfinae_check<correct_size<Ts...>()> = 0>
FBasicParticle(const position_t& pos, Ts&&... ts) :
FBasicParticle(std::make_index_sequence<Dim>(),
std::make_index_sequence<std::tuple_size<data_t>::value-sizeof...(ts)-Dim>(),
......@@ -51,6 +78,21 @@ public:
)
{}
/**
* \brief Failure constructor, make compilation fail when needed
*
* This constructor raises a compilation error if the parameter pack for the
* particle attributes is too long.
*
* \tparam Ts attribute parameter pack
*/
template<typename... Ts,
sfinae_check<!correct_size<Ts...>()> = 0>
FBasicParticle(const position_t&, Ts&&...)
{
static_assert(!sizeof...(Ts), "To many attributes given to particle constructor");
}
/// Constructor from tuple equivalent to #data_t
template<typename... Ts>
FBasicParticle(const std::tuple<Ts...>& ts) :
......@@ -103,6 +145,11 @@ public:
}
private:
/**
* \brief Contructor implementation
*
* Builds the particle, zero constructing missing arguuments.
*/
template<typename... Ts, std::size_t... Is, std::size_t... Js>
FBasicParticle(std::index_sequence<Is...>, std::index_sequence<Js...>,
const FPoint<FReal, Dim>& pos, Ts&&... ts) :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment