BioCMAMC-ST
species_name_extractor.hpp
1#ifndef __SPECIES_NAME_EXTRACTOR_HPP__
2#define __SPECIES_NAME_EXTRACTOR_HPP__
3
4#include <mc/traits.hpp>
5
6namespace impl
7{
8
9 inline auto
10 iota_species(std::size_t n_c)
11 {
12 std::vector<std::string> v(n_c);
13
14 std::generate(
15 v.begin(), v.end(), [n = 0]() mutable { return std::to_string(n++); });
16
17 return v;
18 }
19
20 template <ModelType T>
21 requires(!has_species_name<T>)
22 auto
24 {
25 return iota_species(T::n_c);
26 }
27
28 template <ModelType T>
29 requires has_species_name<T>
30 auto
32 {
33 auto rd = T::species();
34
35 if (rd.size() == 0)
36 {
37 return iota_species(T::n_c);
38 }
39
40 if (rd.size() != T::n_c && rd.size() != 0)
41 {
42 throw std::invalid_argument("Missing species names");
43 }
44
45 return std::vector<std::string>(rd.begin(), rd.end());
46 }
47} // namespace impl
48
49#endif
Definition traits.hpp:58
Definition species_name_extractor.hpp:7
auto iota_species(std::size_t n_c)
Definition species_name_extractor.hpp:10
auto get_species_names_impl()
Definition species_name_extractor.hpp:23