IAP GITLAB

Skip to content
Snippets Groups Projects
Commit f7a61f96 authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan: Committed by ralfulrich
Browse files

made particle name constexpr string_view

parent 88cd957b
No related branches found
No related tags found
1 merge request!280Refactory 2020
......@@ -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)];
}
......
......@@ -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
......
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment