Questions tagged [policy-based-design]
56 questions
4
votes
1 answer
Mechanics of multiple inheritance compared to templates wrt building flexible designs
This is a narrower version of the question put on hold due to being too broad.
On pages 6-7 of Modern C++ Design, Andrei Alexandrescu lists three ways in which the multiple inheritance is weaker than templates with respect to building flexible…

AlwaysLearning
- 7,257
- 4
- 33
- 68
4
votes
2 answers
Policy based design and defaults
Hard to come up with a good title for this question. What I really need is to be able to provide template parameters with different number of arguments in place of a single parameter. Doesn't make a lot of sense so I'll go over the…

Edward Strange
- 40,307
- 7
- 73
- 125
3
votes
1 answer
C++ Copy/Move constructor in policy based design
While exploring Policy Based Design pattern in C++, I stumbled upon one problem which I could not find a solution to: How do you write copy and move constructors for policy based classes in a generic way without referring to member variables inside…

Pranav
- 560
- 1
- 8
- 21
3
votes
1 answer
Java Policy-Based Design
I have a while loop, and the user should be able to decide when the loop stops. After x seconds, after x loops, ... This problem should be implemented according to policy-based design. I know how to do this in C++ but can't get it to work in…

Niel
- 43
- 5
3
votes
3 answers
Policy based design decisions
I have a class called Device that accepts two policies as far as I can see: StatePolicy and BehaviorPolicy.
The StatePolicy holds and manages the state of the device.
The BehaviorPolicy wraps the device driver that is written in C or C++.
Now I have…

the_drow
- 18,571
- 25
- 126
- 193
2
votes
0 answers
Converting a compile-time C callbacks to compile-time C++ callbacks
I'm converting a C codebase to C++ for an embedded device (ESP32). One thing that's repeating in the current code is a way of declaring "callbacks" to C modules and implement them in the "user" module.
For example, the current API for a Button…

galah92
- 3,621
- 2
- 29
- 55
2
votes
1 answer
C++ Template Meta Programming: Inheritance from template template parameter
#include
template
struct mutable_storage {};
template <
template class storage_t,
typename T2 = void,
typename is_allocated =…

Lourens Dijkstra
- 420
- 2
- 11
2
votes
1 answer
Use of unique_ptr in classes with protected destructors
I am studying policy based design from Modern C++ Design, and I have got stuck in a simple example below, where I was trying to use a std::vector of std::unique_ptrs in my templated policy class:
#include
#include
template

enanone
- 923
- 11
- 25
2
votes
1 answer
C++ Policy Based Design
What I do not understand in the Alexandrescu policy based design is the creation of new types without anything in common where, in my opinion, there is still a lot in common that should be represented somehow.
For example, std::string and…

nyarlathotep108
- 5,275
- 2
- 26
- 64
2
votes
2 answers
Policy classes with differing interfaces
Suppose an algorithm that has a policy FooPolicy. Policy classes that implement this policy feature a static member function foo, but, for some of them, foo takes an int argument, while for others it does not. I am trying to enable the use of these…

AlwaysLearning
- 7,257
- 4
- 33
- 68
2
votes
1 answer
Are named template arguments in the newest Standard or implemented in a contemporary compiler?
Named template arguments would arguably be a very important feature in C++. Namely, given a class template that has many template parameters with default arguments, this feature would allow the user to provide arguments for an arbitrary subset of…

AlwaysLearning
- 7,257
- 4
- 33
- 68
2
votes
1 answer
Policy conversion operator vs private destructor in policy-based class
In Modern C++ Design: Generic Programming and Design Patterns Applied Andrei Alexandrescu advocates for making the policies' destructor protected:
Because the destructor is protected, only derived classes can destroy policy objects, so it's…

tsuki
- 907
- 4
- 17
2
votes
1 answer
Run-time polymorphism design and strategies with CRTP
In my work I have a lot of loops with many inner function calls; performance is critical here, and the overhead of virtual function calls is unacceptable, so I try to avoid dynamic polymorphism by using CRTP, like so:
template
struct…

Aurelius
- 1,146
- 2
- 13
- 25
2
votes
2 answers
Ambiguous inheritance in policy-based design
I have a host class, which takes two policies, sayhello and talk. The policy talk is a class template, which itself takes e.g. sayhello.
The problem is that sayhello::saySomething is ambiguous in host2 (i tried to solve this diamond problem with…

the_ducky
- 165
- 1
- 12
2
votes
2 answers
How to realize the policy based design with class mixins?
I know how i can realize a implementation of a class with the policy based design pattern from c++ with Interfaces. I don't know how to do the same with class mixin's.
This would be useful if you want to squeze the last performance out of your code…

Quonux
- 2,975
- 1
- 24
- 32