Похожие чаты

Is there a way to have conditional function depending on

whether a template parameter is true?

Use case: I was making a class that has basically 2 version, 1 basic and 1 advanced. The advanced version is just a bolt on some aspects, while reusing most code for the basic version (except one line of code, I decided to guard it with if constexpr. The problem is, I would not like for the advanced functions to even exist unless it's enabled (there would be inconsistencies). I have added static_assert for checking that atm.
See:
template <typename T, bool ADV = false>
class DS{
private:
...
public:
...
void apply(){
static_assert(ADV);
...
}
void update(){
...
if constexpr(ADV) apply();
...
}
}

I would have instead made the adv version a descendent of basic one (in fact, the relationship is that only) but then I get the problem that I would need to make apply virtual (only solution I could see to not have the descendent have it's own copied of base class's functions, if you have any other idea please tell), which (I may be mistaken, but my search seems to support me) that virtual has performance hits, and this needs to be as efficient as possible.

2 ответов

5 просмотров

I am not totally sure that understand your requirement but maybe this can help you: https://hastebin.com/mehogurebu.cpp Is that you expected?

You can use partial specialization

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

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

А как старый хаскел с новым стыковать ? потому как тут работает https://play.haskell.org/saved/C3xpMzcd, а вот тут https://stepik.org/lesson/7602/step/9?unit=1473 нет ошибка C...
Fedor
131
Guys what is ur real (no jokes) expectation of link price during this cycle?
Hobbyist
22
Hey, it seems like a solid project for the gaming industry. What are your initial thoughts?
Josh
26
Ребят, что лучше для реверса: гидра или ида?
En Vind Av Sorg
26
if (user?.choseType === 'oneDay') { await ctx.reply( 'Добро пожаловать в команду «Магнита»! Правда, на один день ☺️ ', ); await ctx.s...
Kokni
1
Вопрос я правильно понимаю что в коде newtype ArrowMap k v = ArrowMap { getArrowMap :: k -> Maybe v } getArrowMap есть функция типа k -> Maybe v, если да, то не понимаю задач...
Fedor
64
Делаю велосипед логгер. К сообщению хочу прикрутить некоторую информацию, типа, кем отправлено, какой уровень, и всякое такое. И тут подумалось мне, почему бы не хранить весь...
Serjone
24
Всем привет! Использую gitlab-ci. Настроил gitlab-agent для деплоя в куб. При деплое проекта в логах такая ошибка: Executing deploy plan failed to watch "ns:my-project/Ingress...
Konstantin Moiseev
4
Всем добрый вечер, подскажите пожалуйста, я вот вот начинаю пользоваться linux, перешёл с винды и хотелось бы узнать есть ли аналоги onedrive чтобы хранить документы в облаке ...
Malik
14
Как Вы считаете нормально ли в двадцатых годах 21 века в ВУЗах Российской Федерации обучать студентов работе с TASM? Не слишком ли это "архаично"? (Если оффтоп или флейм для э...
Spiker01
52
Карта сайта