4,853 questions
Advice
0
votes
8
replies
381
views
Dynamic list of type at compile time
I'm looking for a way to store type "dynamicly" in a using (or concret implementation) that would be modifable and accessible at compile-time.
I would like something like:
struct ...
11
votes
4
answers
1k
views
C++ template dispatching not calling the correct function
The program test tag dispatching pattern, where the function process_data(tag, a, b) can accept 2 tags int_tag, float_tag. There are 3 case:
int_tag and a, b are int -> print a + b
float_tag and a,...
4
votes
2
answers
541
views
Converting pointer-to-member to member index using Boost.PFR without creating an object
Consider the following struct:
struct Particle
{
float scale;
float opacity;
float rotation;
};
I want the following to compile:
static_assert(indexOf<&Particle::scale>() == 0);
...
526
votes
21
answers
845k
views
Python dictionary from an object's fields
Do you know if there is a built-in function to build a dictionary from an arbitrary object? I'd like to do something like this:
>>> class Foo:
... bar = 'hello'
... baz = 'world'
...
...
2
votes
1
answer
165
views
Using C++ macros to construct a method name to call
I have a class Foo from a third party library that has a lots of setters with a string argument named as set_parameter_name(std::string value). And I need to configure an instance of the class using a ...
1
vote
0
answers
98
views
Is it possible to bound type-level recursion?
I'm trying to construct a typed lambda calculus, something along the lines of:
struct Fun<T>(T); // actual definition elided for simplicity
struct TypeErasedExpr { /* elided for simplicity */ }
...
-1
votes
1
answer
205
views
Typename packing is failed in C++
Here is code:
aml::type_list<int,int,char,std::string> example;
std::tuple_element_t<2,std::tuple<decltype(example)>> a = 'b';
But when i try to run code it says, static assertion ...
9
votes
3
answers
973
views
How to constrain a C++ template template argument to be a child of a templated type?
In the snippet below, base_type_t has 2 template arguments; T1 and k1. The templates foo_t, bar_t, and baz_t derive from this base, using the derived template's parameter for T1, but providing a ...
-1
votes
1
answer
142
views
Why template instantiation requires specialation in the case where it is already done for all cases?
In c++ when i try to write a code that returns reverse of a type list what i wrote( a user defined template class):
template <typename ...V,typename ...D>
constexpr decltype(auto) merge(...
8
votes
1
answer
199
views
Making a type trait for rotating index_sequences more compiler friendly
I've created a type trait to create a type pack of rotating index sequences:
#include <cstddef>
#include <utility>
template <class...>
struct type_pack {};
template <size_t N>...
0
votes
1
answer
250
views
How to verify that obscure Python behavior is by design
I’ve been experimenting in order to deepen my understanding of Python metaprogramming, and I have noticed a potentially useful behavior that I cannot find documentation to explain, so I don’t know ...
2
votes
2
answers
242
views
How can I make all attributes in a Python dataclass optional without rewriting each one?
I have this data class:
@dataclass
class User:
id: str
name: str
pwd: str
picture: str
url: str
age: int
# many, many more attributes
Now, I have to make all of the ...
7
votes
1
answer
226
views
Why does monkey patching a class's `__new__` not (always) work?
I am trying to do some monkey patch work on an existing third-party library I am using.
Summary
This sequence does not work:
Monkey patch A.__new__ using mynew
Monkey patch A.__new__ again using ...
0
votes
1
answer
58
views
Line-by-Line Formula Parsing and Exploration of Metaprogramming
I want to parse and calculate formulas line by line. The formulas depend on the given variables x1 and x2. The number of formulas per line is not fixed, and there are dependencies between the results ...
1
vote
1
answer
271
views
Using C++26 reflection's to inject a struct's name into another struct?
To better understand C++26's reflection, I would like to understand how we can reflect on the name of a struct to inject it in another one (potentially replacing its body, just keeping the name)
For ...