diff --git a/src/core/data/ions/ion_population/ion_population.hpp b/src/core/data/ions/ion_population/ion_population.hpp index f63f1c7f0..aa6554e47 100644 --- a/src/core/data/ions/ion_population/ion_population.hpp +++ b/src/core/data/ions/ion_population/ion_population.hpp @@ -1,18 +1,15 @@ #ifndef PHARE_ION_POPULATION_HPP #define PHARE_ION_POPULATION_HPP -#include -#include -#include -#include #include -#include +#include +#include #include "core/def.hpp" -#include "core/hybrid/hybrid_quantities.hpp" -#include "initializer/data_provider.hpp" #include "particle_pack.hpp" +#include "initializer/data_provider.hpp" +#include "core/hybrid/hybrid_quantities.hpp" namespace PHARE { @@ -52,15 +49,13 @@ namespace core NO_DISCARD bool isUsable() const { - return particles_.isUsable() && rho_.isUsable() && flux_.isUsable() - && momentumTensor_.isUsable(); + return core::isUsable(particles_, rho_, flux_, momentumTensor_); } NO_DISCARD bool isSettable() const { - return particles_.isSettable() && rho_.isSettable() && flux_.isSettable() - && momentumTensor_.isSettable(); + return core::isSettable(particles_, rho_, flux_, momentumTensor_); } NO_DISCARD auto& domainParticles() const { return particles_.domainParticles(); } diff --git a/src/core/data/ions/ion_population/particle_pack.hpp b/src/core/data/ions/ion_population/particle_pack.hpp index 485c3d53b..da3c14098 100644 --- a/src/core/data/ions/ion_population/particle_pack.hpp +++ b/src/core/data/ions/ion_population/particle_pack.hpp @@ -1,6 +1,7 @@ #ifndef PHARE_CORE_DATA_PARTICLES_PARTICLE_PACK_HPP #define PHARE_CORE_DATA_PARTICLES_PARTICLE_PACK_HPP +#include "core/def.hpp" #include "core/data/particles/particle_array.hpp" namespace PHARE @@ -36,25 +37,16 @@ namespace core auto& name() const { return _name; } - auto _as_tuple() const - { - return std::forward_as_tuple(_domainParticles, _patchGhostParticles, - _levelGhostParticles); - } NO_DISCARD bool isUsable() const { - auto tup = _as_tuple(); - return for_N_all>( - [&](auto i) { return std::get(tup) != nullptr; }); + return core::isUsable(_domainParticles, _patchGhostParticles, _levelGhostParticles); } NO_DISCARD bool isSettable() const { - auto tup = _as_tuple(); - return for_N_all>( - [&](auto i) { return std::get(tup) == nullptr; }); + return core::isSettable(_domainParticles, _patchGhostParticles, _levelGhostParticles); } diff --git a/src/core/def.hpp b/src/core/def.hpp index 4c190814b..e6eb3d6ed 100644 --- a/src/core/def.hpp +++ b/src/core/def.hpp @@ -1,8 +1,15 @@ #ifndef PHARE_CORE_DEF_HPP #define PHARE_CORE_DEF_HPP +#include + #define NO_DISCARD [[nodiscard]] +#if !defined(NDEBUG) || defined(PHARE_FORCE_DEBUG_DO) +#define PHARE_DEBUG_DO(...) __VA_ARGS__ +#else +#define PHARE_DEBUG_DO(...) +#endif #define _PHARE_TO_STR(x) #x // convert macro text to string #define PHARE_TO_STR(x) _PHARE_TO_STR(x) @@ -10,4 +17,32 @@ #define PHARE_TOKEN_PASTE(x, y) x##y #define PHARE_STR_CAT(x, y) PHARE_TOKEN_PASTE(x, y) + +namespace PHARE::core +{ +template +NO_DISCARD bool isUsable(Args const&... args) +{ + auto check = [](auto const& arg) { + if constexpr (std::is_pointer_v>) + return arg != nullptr; + else + return arg.isUsable(); + }; + return (check(args) && ...); +} + +template +NO_DISCARD bool isSettable(Args const&... args) +{ + auto check = [](auto const& arg) { + if constexpr (std::is_pointer_v>) + return arg == nullptr; + else + return arg.isSettable(); + }; + return (check(args) && ...); +} +} // namespace PHARE::core + #endif // PHARE_CORE_DEF_HPP diff --git a/src/core/utilities/types.hpp b/src/core/utilities/types.hpp index 412456da7..ee90667ad 100644 --- a/src/core/utilities/types.hpp +++ b/src/core/utilities/types.hpp @@ -19,14 +19,7 @@ #include "cppdict/include/dict.hpp" -#if !defined(NDEBUG) || defined(PHARE_FORCE_DEBUG_DO) -#define PHARE_DEBUG_DO(...) __VA_ARGS__ -#else -#define PHARE_DEBUG_DO(...) -#endif - -#define _PHARE_TO_STR(x) #x // convert macro text to string -#define PHARE_TO_STR(x) _PHARE_TO_STR(x) + namespace PHARE {