Похожие чаты

Hi guys I have a conceptual map of string to

type like

"1", typeClass1
"2",typeClass2
...

Now depending on the string I want to call the function of mapped type, is it possible to do it using templates and not a if then else tree ?

Looking for one liner or short templated form of the if then else tree I would create matching the string and routing to specific type..

So how to generate the actual map and compressed templates router

2 ответов

6 просмотров

You could test something like: template <typename T> void foo(std::string s, T t) { std::map<std::string, T> mp; // ... } And inside the function check for properties of the T using e.g., requires. This page has useful info: https://akrzemi1.wordpress.com/2020/01/29/requires-expression/

You can't use a std::string. You can use a class that you create which has compile time properties that allows string comparison and then use that class as the key for the map

Похожие вопросы

Обсуждают сегодня

А как старый хаскел с новым стыковать ? потому как тут работает https://play.haskell.org/saved/C3xpMzcd, а вот тут https://stepik.org/lesson/7602/step/9?unit=1473 нет ошибка C...
Fedor
131
Вопрос я правильно понимаю что в коде newtype ArrowMap k v = ArrowMap { getArrowMap :: k -> Maybe v } getArrowMap есть функция типа k -> Maybe v, если да, то не понимаю задач...
Fedor
64
I am honored to report that all the deliverables for the BCHFAQ Flipstarter Phase 1 have been completed. I appreciate the opportunity I've had to put all this together using t...
fixthetracking
15
Как Вы считаете нормально ли в двадцатых годах 21 века в ВУЗах Российской Федерации обучать студентов работе с TASM? Не слишком ли это "архаично"? (Если оффтоп или флейм для э...
Spiker01
52
Hey guys, I'm new in this group, but I've had DVPN for a little while now. Any new updates or anything to look forward to? How we feeling about everything?
Steve G
16
Продолжая диалог про свифт в проде – сейчас возник вопрос в активном наборе бекендеров. В основном в нашей компании мы фанаты Java Spring и полностью ей довольны. Однако найм ...
Guseyn
27
Кто-нибудь знает, как считается нагрузка на цпу? И что такое вообще "нагрузка на цпу"? вот, например, есть у цпу какой-то clock, настроенный на 3 ГГц --- Что значит "нагрузка...
Toideng
15
Можно ли написать свою библиотеку "socket" на каком либо языке ассемблера с нуля не используя сишние библиотеки ? Или это самоубийство ?
123🪐
15
Is there any new news from Kadena? The price is very suppressed.
HAKAN TECİMEN
27
Комрады, хотел уточнить. Проперть в OnDestroy юнита-хозяина по-прежнему доступна? И еще уточнение: finalization юнита наступает раньше или позже OnDestroy?
Ed Doc
48
Карта сайта