Похожие чаты

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 ответов

9 просмотров

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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта