diff --git a/corsika/detail/framework/core/ParticleProperties.inl b/corsika/detail/framework/core/ParticleProperties.inl index 254498a1d9e5d96e943e993808cd424b07b890e1..be54dc1840a40194d2485c15ade464a5eee61c90 100644 --- a/corsika/detail/framework/core/ParticleProperties.inl +++ b/corsika/detail/framework/core/ParticleProperties.inl @@ -33,7 +33,7 @@ namespace corsika { return get_charge_number(code) * constants::e; } - constexpr std::string const& get_name(Code const code) { + constexpr std::string_view get_name(Code const code) { return particle::detail::names[static_cast<CodeIntType>(code)]; } diff --git a/corsika/framework/core/ParticleProperties.hpp b/corsika/framework/core/ParticleProperties.hpp index 6c613d184288986412ccd56120e7dd468f28e5a3..801447944b722be95307baf1cfb0fc8ecb999853 100644 --- a/corsika/framework/core/ParticleProperties.hpp +++ b/corsika/framework/core/ParticleProperties.hpp @@ -18,6 +18,8 @@ #include <cstdint> #include <cmath> #include <iosfwd> +#include <string_view> +#include <type_traits> #include <corsika/framework/core/PhysicalUnits.hpp> @@ -45,7 +47,7 @@ namespace corsika { //! Particle code according to PDG, "Monte Carlo Particle Numbering Scheme" PDGCode constexpr get_PDG(Code); - constexpr std::string const& get_name(Code); //!< name of the particle as string + constexpr std::string_view get_name(Code); //!< name of the particle as string TimeType constexpr get_lifetime(Code); //!< lifetime //! true iff the particle is a hard-coded nucleus or Code::Nucleus diff --git a/src/framework/core/pdxml_reader.py b/src/framework/core/pdxml_reader.py index 0753325e2f0ffc1e77b465047f124d6a81def817..fcd0b134187647d81bf747c3634e4dce2eb76a57 100755 --- a/src/framework/core/pdxml_reader.py +++ b/src/framework/core/pdxml_reader.py @@ -338,7 +338,7 @@ def gen_properties(particle_db): string += "};\n" # name string table - string += "static const std::array<std::string const, size> names = {\n" + string += "static constexpr std::array<std::string_view, size> names = {\n" for p in particle_db.values(): string += " \"{name:s}\",\n".format(name = p['name']) string += "};\n" @@ -434,7 +434,7 @@ def gen_classes(particle_db): string += " static constexpr HEPMassType mass{corsika::get_mass(code)};\n" string += " static constexpr ElectricChargeType charge{corsika::get_charge(code)};\n" string += " static constexpr int charge_number{corsika::get_charge_number(code)};\n" - string += " inline static std::string const& name{corsika::get_name(code)};\n" + string += " static constexpr std::string_view name{corsika::get_name(code)};\n" string += " static constexpr bool is_nucleus{corsika::is_nucleus(code)};\n" if particle_db[cname]['isNucleus']: string += " static constexpr int nucleus_A{corsika::get_nucleus_A(code)};\n"