metaprogramming Questions
7
Solved
I have some classes which only serve to contain data. For example
public class EntityAdresse : IEntityADRESSE
{
public string Name1 { get; set; }
public string Strasse { get; set; }
public stri...
Ranchman asked 6/3, 2013 at 10:5
2
I need to write a dplyr function that creates a customised area plot. So here's my attempt.
area_plot <- function(data, what, by){
by <- ensym(by)
what <- ensym(what)
data %>%
f...
Surreptitious asked 16/10, 2018 at 12:34
5
Solved
Most of my classes have debug variables, and this makes them often look like this:
class A
{
// stuff
#ifndef NDEBUG
int check = 0;
#endif
};
and methods might look like this:
for (/* big loo...
Vanessa asked 16/2, 2011 at 13:36
2
Solved
I have a Singleton object in Python:
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__ca...
Silencer asked 25/4, 2017 at 19:51
7
Solved
Is it possible to get the class name within the body of a class definition?
For example,
class Foo():
x = magic() # x should now be 'Foo'
I know that I can do this statically outside of the cl...
Piles asked 15/7, 2011 at 17:27
4
Solved
For example, if I execute a Groovy script, which modifies the String meta class, adding a method foo()
GroovyShell shell1 = new GroovyShell();
shell1.evaluate("String.metaClass.foo = {-> delega...
Homograph asked 23/10, 2009 at 10:25
4
Is there any way to map enum values to types in C++, including C++11.
I have the following enum type:
enum ATTRIBUTE{AGE=0, MENOPAUSE, TUMOR_SIZE, INV_NODES, NODE_CAPS,
DEG_MALIG, BREAST, BREAST_...
Bounty asked 1/1, 2017 at 11:57
5
Solved
Is it possible in C++ to determine number of variables/fields in the generic class?
for example
// suppose I need metaclass number_members determines number of members
struct example { int i, j; ...
Macrae asked 7/4, 2010 at 3:41
3
Solved
I would like to create a new Enum (IntEnum) class based on two existing ones. There is a working solution for this, like so:
from enum import unique, IntEnum
from itertools import chain
from colle...
Carycaryatid asked 6/9, 2017 at 10:56
5
Solved
I've been on this problem all morning with no result whatsoever.
Basically, I need a simple metaprogramming thing that allows me to branch to different specializations if the parameter passed is a ...
Astatic asked 2/5, 2013 at 12:3
2
I am attempting to take the source code of a function, add code to it, and then put it back in the original function.
Basically like so:
new_code = change_code(original_code)
throwaway_module = M...
Posthumous asked 9/2, 2019 at 1:26
1
Solved
I would like to be able to add a sub to a module Foo at runtime.
In Perl, I would do something like:
*{'My::Module::foo'} = \sub { 'FOO!' };
I know Raku doesn't have TypeGlobbing like Perl. Ideall...
Adularia asked 17/3 at 15:15
3
Solved
I would like to know if it is possible to retrieve the name of a variable.
For example if I have a method:
def printSomething(def something){
//instead of having the literal String something, I ...
Jenness asked 2/4, 2019 at 16:38
1
How do tools like dataclasses and pydantic create the __init__() functions for the classes they create?
I know I can use these tools but I want to learn how to use the python metaprogramming to par...
Mikesell asked 19/2 at 9:12
5
Solved
I'm doing some metaprogramming in Ruby, and I need to dynamically generate a sibling class inside of a module. In doing so, I want to call const_set on the module, but I don't know which Module con...
Mendie asked 1/6, 2011 at 21:34
5
I have a DSL in Ruby that works like so:
desc 'list all todos'
command :list do |c|
c.desc 'show todos in long form'
c.switch :l
c.action do |global,option,args|
# some code that's not relevan...
Berti asked 1/5, 2011 at 20:20
2
Solved
I have tried to create a compile-time simple Key-Value map in C++. I'm compiling with /std:c++11.
(Using IAR compiler for embedded code and only cpp++11 is supported at the moment)
I've learnt a l...
Recitative asked 17/4, 2020 at 22:39
6
Following code works in GCC (at least in GCC 10.1.0), but not in MSVC and Clang. I'm not sure if it's legal in C++ standard.
I'm trying to count the parameters in a template template type.
Is the f...
Maemaeander asked 13/8, 2020 at 16:6
6
Solved
Given a lambda, is it possible to figure out it's parameter type and return type? If yes, how?
Basically, I want lambda_traits which can be used in following ways:
auto lambda = [](int i) { retur...
Demmer asked 30/10, 2011 at 5:47
21
Solved
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'
...
>...
Santinasantini asked 14/9, 2008 at 18:0
21
Solved
Being able to create and manipulate strings during compile-time in C++ has several useful applications. Although it is possible to create compile-time strings in C++, the process is very cumbersome...
Johannessen asked 7/4, 2013 at 2:10
2
Solved
I need to test if two types are equal in const fn. Comparing the TypeId doesn't work:
#![feature(const_if_match)]
#![feature(const_fn)]
#![feature(const_type_id)]
const fn t<T1: 'static, T2: '...
Helminth asked 9/2, 2020 at 15:49
5
Given a class definition in C++
class A
{
public:
//methods definition
....
private:
int i;
char *str;
....
}
Is it possible to calculate the offset of a class member at compile time usi...
Impure asked 1/11, 2012 at 15:59
6
Solved
How do I find out if a variable has been defined in my Robot Framework script? I am doing API testing, not UI testing. I have a complex set up and tear-down sequence and, since I am interacting wit...
Grider asked 15/11, 2019 at 20:49
3
Solved
This is more of a conceptual question. I'm trying to find the easiest way of converting a two-arg template (the arguments being types) into a one-arg template. I.e., binding one of the types.
This...
Setiform asked 25/11, 2014 at 10:45
1 Next >
© 2022 - 2024 — McMap. All rights reserved.