Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
58 views

The following code works: fn do_it_fun<I>(words: Vec<&str>, inputs: I) where I: AsRef<[&'static str]> { for word in words { if inputs.as_ref().into_iter()...
gust's user avatar
  • 965
1 vote
2 answers
111 views

I want to store several different callable objects (different types) in a container (e.g. std::array) in order to invoke them later. Each callable has the same return type and the same amount and type ...
breiters's user avatar
  • 158
0 votes
1 answer
75 views

This a snippet from the real code, but the idea is that i want to print the service type in my log. In this example i'm trying to print it, but i get an exception, and i don't know why. I have other ...
eniac's user avatar
  • 63
1 vote
1 answer
159 views

In order to store CRTP object pointers in a homogenous container the templated base class can itself be derived from a class common_base that defines a pure virtual interface and (if required) a ...
sleep's user avatar
  • 4,974
3 votes
2 answers
3k views

I wonder if there is any benefit of using CRTP over virtual function polymorphism if I never invoke the function from the base class (i.e., virtual dispatch)? Here are the sample code. The disassembly ...
Yuanyi Wu's user avatar
  • 339
0 votes
1 answer
155 views

My questions are: Why method hiding is also an example of compile time polymorphism while it is not overridden? Related code: class A{ public static void print(){ System.out.println("...
tú nguyệt's user avatar
1 vote
1 answer
394 views

If you want to have different public interfaces for one and the same object, you can use virtual base classes. But those have overhead (memory and space). class View1 { public: int x; } class ...
Sebastian's user avatar
  • 2,014
0 votes
1 answer
342 views

Let's say I have following C++ code class ControlAlgorithm { public: virtual void update() = 0; virtual void enable() = 0; virtual void disable() = 0; }; class Algorithm_A : public ...
Steve's user avatar
  • 869
1 vote
1 answer
385 views

I want to implement the template method pattern using static polymorphism in C++. Right now I have two classes A and B which are very similar. They have an identical public API and the exact same list ...
JonatanE's user avatar
  • 951
0 votes
1 answer
687 views

I'm trying to implement something like static polimorphism using std::variant. I want to declare methods using VARIANT_METHOD or VARIANT_METHOD_CONST, that should take return type, method name, ...
Maksym Pasichnyk's user avatar
1 vote
0 answers
152 views

An event/task instance is created based on some incoming data in a thread and is sent to be processed in another thread. I'm trying to measure different implementations of processing those events in ...
trytt's user avatar
  • 61
1 vote
0 answers
60 views

Let's say I'm writing a library and at some point, there is code that wants to do something specific with objects of user-provided types. Take swap as an example, although the function could be ...
Xeverous's user avatar
  • 1,013
1 vote
2 answers
3k views

Often when writing templated code, I find myself needing to store an instance of the template type in a member variable. For example, I might need to cache a value to be used later on. I would like to ...
pooya13's user avatar
  • 2,859
0 votes
0 answers
128 views

I have encountered an incomplete type error in designing my library's CRTP inheritance structure. I am cognizant of the fact that this might possibly be solved by way of type traits but I do not even ...
Tom Porter's user avatar
3 votes
2 answers
158 views

I am trying to use static polymorphism like in the simple example shown below. #include <iostream> template <typename Derived> struct Base { decltype(auto) foo() { return static_cast&...
Petok Lorand's user avatar
2 votes
2 answers
73 views

I have this piece of code: #include <iostream> template<class T> void* ToPtr(T t) { return ToPtr((void*)t); } void* ToPtr(void* i) { return i; } void* ToPtr(int i) { return (void*)(long)(...
dromodel's user avatar
  • 10.4k
3 votes
2 answers
631 views

I'm trying to use the static polymorphism and template to create a container that can hold more the one type, from what I know about template it can't be done, but I'm hoping that I'm wrong and there ...
yaodav's user avatar
  • 1,296
0 votes
1 answer
226 views

Why method overloading called as static or compile-time polymorphism sample in Java. class StaticPolymorphismSample { void polymorphicMethod(int a) { } void polymorphicMethod(int a, int ...
Hayk Melkonyan's user avatar
0 votes
1 answer
483 views

I'm implementing a static polymorphism: template<typename T> class Base { public: void method() { // do something impl(); // do something else } void impl(...
beginpluses's user avatar
0 votes
1 answer
898 views

I'm trying to use static polymorphism instead of dynamics polymorphism with Qt signal/slot mechanism. But I get compile error. What is wrong in my code? What is workaround? devices.h #ifndef ...
mas sam's user avatar
  • 21
4 votes
4 answers
714 views

I have multiple classes containing duplicated code, especially members and most important a static method that will create a new instance of the class and returning this instance: either a previously ...
plm36021's user avatar
0 votes
0 answers
278 views

WRONG QUESTION. EXAMPLE CODE WORKS. Consider this code export interface IParameterType{ name:string, label:string, type:string, defaultValue:number } class Object3D{ public static ...
Alberto Valero's user avatar
-1 votes
1 answer
254 views

I'm wondering about the available alternatives to run-time polymorphism, specifically, an alternative to having a common base class between my classes in order to store and interact with instances of ...
nitronoid's user avatar
  • 1,659
0 votes
1 answer
83 views

I have a class A that is a child of class B, I need all children of class B to have a function pointer to a function for handling the class that is changeable by an external function in a different ...
Jesse McDonald's user avatar
0 votes
1 answer
407 views

I use CRTP static polymorphism in a websocket server to decouple networking code from business logic. The base class calls methods on the derived to process messages, the derived in turn calls the ...
Gyorgy Szekely's user avatar