Questions tagged [policy-based-design]
56 questions
62
votes
5 answers
What is the difference between a trait and a policy?
I have a class whose behavior I am trying to configure.
template ServerTraits;
Then later on I have my server object itself:
template
class Server {…};
My question is for my usage above…

Nathan Doromal
- 3,437
- 2
- 24
- 25
37
votes
4 answers
Policy based design and best practices - C++
struct InkPen
{
void Write()
{
this->WriteImplementation();
}
void WriteImplementation()
{
std::cout << "Writing using a inkpen" << std::endl;
}
};
struct BoldPen
{
void Write()
{
std::cout << "Writing using a boldpen"…

Navaneeth K N
- 15,295
- 38
- 126
- 184
14
votes
5 answers
C++11 templates, determining return type
I am building a matrix library and I am trying to use the policy-based design.
So my base classes are classes that provide a storage method and some
access functions.
I also have a function matrix which provides the mathematical functions.
This…

Sparky
- 717
- 1
- 7
- 17
13
votes
2 answers
How to use typelists
I read about typelists in 'Modern C++ Design' and I understood it as some kind of union for types. By putting diffrent, non-related types in a typelist, one can use it to represent more than one type at once, without inheritance. I tested typelist…

DaClown
- 4,171
- 6
- 31
- 31
8
votes
0 answers
Understanding the exposition of Alexandrescu about the weaknesses of multiple inheritance
UPDATE: I have asked a narrower question here.
On pages 6-7 of Modern C++ Design, Andrei Alexandrescu gives a very fundamental discussion of the strengths and weaknesses of two C++ language features -- multiple inheritance and templates -- with…

AlwaysLearning
- 7,257
- 4
- 33
- 68
7
votes
1 answer
C++ policy based design: Inheritance vs composition
At Meeting C++ 2019, Jon Kalb gave a talk about template techniques and mentioned policy classes. See here for the source: https://youtu.be/MLV4IVc4SwI?t=1815
The interesting code snippet in question is:
template

flowit
- 1,382
- 1
- 10
- 36
6
votes
2 answers
Preserving the implicitness of construction in a policy-based class
Consider a policy-based smart pointer class Ptr with only one policy that will prevent dereferencing it in a NULL state (somehow). Let's consider 2 policies of this kind:
NotNull
NoChecking
Since the NotNull policy is more restrictive, we would…

tsuki
- 907
- 4
- 17
6
votes
2 answers
Does static polymorphism make sense for implementing an interface?
and Merry Christmas everybody!
I am learning about static polymorphism and I'm reading Andrei Alexandrescu's excellent book on policy-based design. I came across the following, in my code: I have interface Interface which specifies that method Foo…

Dan Nestor
- 2,441
- 1
- 24
- 45
6
votes
2 answers
Policy based approach with logger
I spend some time with redesigning a logger class I did once into a policy based approach after reading an article about policy based design and wanting to try something myself.
Some code:
template
…

Chris
- 1,226
- 1
- 12
- 26
5
votes
2 answers
Partial specialization for a parent of multiple classes
I want to use partial specialization for a template class so that all children of that template class will use that specialization. Let me explain it with an example :)
template < typename T, unsigned int rows, unsigned int cols>
class BaseMatrix…

Sparky
- 717
- 1
- 7
- 17
5
votes
0 answers
Is Mixin a special case of Policy-Based Design?
As far as I know, mixin is when you first write the derived class, and then you can inject the base class to it through a template parameter.
Example: http://www.drdobbs.com/cpp/mixin-based-programming-in-c/184404445
As I know Policy-based design is…

Melkon
- 418
- 3
- 12
5
votes
1 answer
Policy Based Design with Variadic Templates
I have a set of homogeneous policy classes that I want to pass as policies to a template class, PolicyDrivenClass, which takes some unknown number of policy template parameters.
Each policy implements a "name" function, and I would like to be able…

Craig Wright
- 1,575
- 1
- 11
- 19
4
votes
1 answer
What is a good tutorial for C++ policy-based class design?
I have just started reading Modern C++ Design Generic programming and Design Patterns Applied and I am wondering if I need to go through some very basic tutorial on policy-based class design before I dive in. Will chapter 1 provide all I need to…

dubnde
- 4,359
- 9
- 43
- 63
4
votes
2 answers
Dispatch on execution policy by type or enum?
In C++ I basically have two choices in policy based design patterns: I can use individual types (based on which an overload is selected) or specify an enum that contains all policies and I would dispatch over them at runtime. What is the preferred…

glades
- 3,778
- 1
- 12
- 34
4
votes
1 answer
What are the measures to call a Python code a policy-based design?
Description
I wonder if the code I am showing can be considered as an example of policy-based design in Python. Also, I would like to know if have you seen python modules using something like this example so I can learn from them?
I wrote more…

Victor Bazterra
- 161
- 1
- 4