fork download
  1. #include <string>
  2. #include <map>
  3. #include <set>
  4. #include <initializer_list>
  5.  
  6. using namespace std;
  7.  
  8. class A
  9. {
  10. public:
  11. struct pair_type // or use std::pair
  12. {
  13. long val;
  14. std::string desc;
  15. };
  16.  
  17. A(initializer_list<A::pair_type>);
  18.  
  19. private:
  20. map<long, string> _valueMap;
  21. map<string, long> _descriptionMap;
  22. set<string> _descriptions;
  23. set<long> _values;
  24. };
  25.  
  26. A::A(initializer_list<A::pair_type> l)
  27. {
  28. for (auto & elem : l)
  29. {
  30. _valueMap.emplace(elem.val, elem.desc);
  31. _descriptionMap.emplace(elem.desc, elem.val);
  32. _descriptions.emplace(elem.desc);
  33. _values.emplace(elem.val);
  34. }
  35. }
  36.  
  37.  
  38. class B
  39. {
  40. enum { abbreviation, name, number, numberOfNameOptions };
  41.  
  42. public:
  43. static A& getType();
  44. };
  45.  
  46. A& B::getType()
  47. {
  48. static A a =
  49. {
  50. { abbreviation, "abbreviation" },
  51. { name, "name" },
  52. { number, "number" },
  53. { numberOfNameOptions, "numberOfNameOptions" }
  54. };
  55.  
  56. return a;
  57. }
  58.  
  59. int main()
  60. {
  61. B b ;
  62. A a = b.getType() ;
  63. }
  64.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Standard output is empty