10,431 questions
Best practices
0
votes
3
replies
94
views
Code design conundrum: runtime polymorphism, templates, compile times, and OpenMP
I'm struggling to finalise the design of my C++17 library.
One of the primary goals is to use runtime polymorphism to allow users to extend or rewrite default features of the library for their own use ...
3
votes
1
answer
130
views
Why can’t I efficiently move-construct `std::polymorphic<Base>` from `std::polymorphic<Derived>`?
As I understand it, std::polymorphic<T> and std::indirect<T> are const-propagating wrapper types for an owning pointer to a T object, where the target of the pointer is copied with the ...
3
votes
2
answers
92
views
Automatically set timestamps on polymorphic relation table
I have a ProductLandedCost model with a morphToMany relationship to various other models: Warehouse, for example:
class Warehouse extends Model
{
// ...
public function productLandedCosts(): ...
2
votes
3
answers
119
views
How to Unit Test Multi-Stage Member Functions in Polymorphic Classes Used with std::variant?
I have three processor classes that share a common interface for polymorphic behavior using std::variant and std::visit. Each processor has a processData() member function that internally consists of ...
2
votes
2
answers
210
views
Is it possible/how to let parent class thread invoke function in child class that overrides parent function?
I am trying to implement a Parent and Child class. The Parent class would start a thread and run a routine function. The Child class would override the routine function if needed.This seems perfectly ...
Best practices
1
vote
6
replies
225
views
Base class and derived classes in Qt
I'm building a Qt wrapper for RtMidi. As starting point I created two separate classes QMidiOut and QMidiIn that wrap RtMidiOut and RtMidiIn.
I don't want to duplicate code for the common methods (e.g....
5
votes
1
answer
140
views
What is the formal name for GHC automatically adapting less-constrained functions to more-constrained rank-2 arguments? [closed]
Consider this Haskell code that compiles successfully:
{-# LANGUAGE RankNTypes #-}
-- Applies a polymorphic function to different types, expecting 3 constraints
applyToMany :: (forall a. (Show a, Eq ...
0
votes
0
answers
65
views
Issues with polymorphis in Swagger (springdoc) in Spring Boot after upgrading to 3.5
I have created a very simple demo project with one controller endpoint:
Spring Boot 3.5.6
Springdoc 2.8.13
This was working much better in Spring Boot 2.7.x
Full project here: https://github.com/...
-1
votes
3
answers
196
views
Python function change behaviour depending on type of argument
I'm playing around with OOP in Python, and I have something like this:
class Person:
def __init__(self,name, age):
self.name = name
self.age = age
self.hobbies = []
...
0
votes
2
answers
69
views
MyIntListImpl is not abstract and does not override abstract method getItem() in IMyDummyList [duplicate]
I don't understand why my class that extends an abstract class (which implements an interface) does not override the interface's single method. I get this error when I try to compile:
MyIntListImpl ...
0
votes
0
answers
164
views
How to reproduce C++ deleting destructor for a custom allocator?
I am aware that calling delete this in a member function is not UB in itself. In fact, compiler is doing the very same thing when one calls delete ptr, ptr being a pointer to a polymorphic object (...
1
vote
1
answer
111
views
Polymorphic deserialize JSON using DI container to create instances
Consider these model classes:
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(A), typeDiscriminator: nameof(A))]
[JsonDerivedType(typeof(B), ...
3
votes
1
answer
99
views
What does "single run-time representation" mean in Bjarne Stroustrup's description of type erasure in "The C++ Programming Language"?
In The C++ Programming Language - 4th edition, in §25.3 at page 731-732 Bjarne Stroustrup shows a possible implementation of a Vector template class that's been specialized for all T* template ...
1
vote
0
answers
72
views
Kotlin serialize simple class with explicit Serial Name
I've tried to use kotlinx.serialization with the third party Yaml plugin from @charleskorn.
In the past I already did something with Python using pyyaml, where I explicitly set a custom yaml_tag for ...
3
votes
2
answers
114
views
Is casting from a pointer polymorphic base object to pointer to a derived object via explicit cast and accessing only functions ill-formed? [duplicate]
Given a base/derived class polymorphic relationship (established below via the virtual destructor), if I explicitly (C-style) cast a pointer-to-a-base object to a pointer-to-a-derived object, is this ...