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,...
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 */ }
...
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 ...
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 ...
-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 ...
-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(...
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);
...
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 ...
0
votes
0
answers
22
views
How to resolve metaprogramming function when variable is indirectly assigned a function name?
I'm working with metaprogramming in Python and need to dynamically resolve functions. When a variable is directly assigned a function name, everything works. However, when assigned indirectly via ...
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 ...
4
votes
1
answer
76
views
__new__ function behaves differently after overriding it with setattr
I have the following:
class A:
def __init__(self, x):
self.x = x
A(5) # Works fine
x = A.__new__ # Save the function
A.__new__ = lambda y: y # Temporarily override it
A.__new__ = x # ...
1
vote
0
answers
58
views
Why does SQL meta-programming using macro variables fail
I have an in-memory table defined as follows in DolphinDB:
t = table(2025.01.01 as date, 1 as M01, 2 as M02, 3 as M03, 4 as M04, 5 as M05, 6 as M06, 1 as M07, 2 as M08, 3 as M09, 4 as M10, 5 as M11, 6 ...
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>...
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 ...