Skip to main content
148 votes
6 answers
38k views

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) { return ...
Sarfaraz Nawaz's user avatar
34 votes
5 answers
10k views

Consider the following code: >>> class A(object): ... pass ... >>> def __repr__(self): ... return "A" ... >>> from types import MethodType >>> a = ...
James Mills's user avatar
  • 19.1k
117 votes
5 answers
91k views

How can I call a method dynamically when its name is contained in a string variable? For example: class MyClass def foo; end def bar; end end obj = MyClass.new str = get_data_from_user # e.g. `...
user502052's user avatar
  • 15.3k
179 votes
5 answers
83k views

I am aware of how to create getters and setters for properties whose names one already knows, by doing something like this: // A trivial example: function MyObject(val){ this.count = 0; this....
daiscog's user avatar
  • 12.2k
80 votes
12 answers
40k views

For the purpose of introspection, sometimes I've wanted to automatically assign serial numbers to types, or something similar. Unfortunately, template metaprogramming is essentially a functional ...
Potatoswatter's user avatar
166 votes
21 answers
113k views

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, ...
void-pointer's user avatar
  • 15.1k
119 votes
12 answers
72k views

I have read in few different places that using C++11's new string literals it might be possible to compute a string's hash at compile time. However, no one seems to be ready to come out and say that ...
deft_code's user avatar
  • 59.9k
63 votes
1 answer
5k views

One of my most beloved/evil inventions I've had the fortune to come across is the constexpr counter, aka stateful metaprogramming. As mentioned in the post, it seems to be legal under C++14, and I'm ...
Passer By's user avatar
  • 21.6k
79 votes
14 answers
50k views

One can define a static array at compile time as follows: const std::size_t size = 5; unsigned int list[size] = { 1, 2, 3, 4, 5 }; Question 1 - Is it possible by using various kinds of ...
Hippicoder's user avatar
  • 1,615
526 votes
21 answers
845k views

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' ... ...
Julio César's user avatar
  • 13.4k
230 votes
5 answers
86k views

$0 is the variable for the top level Ruby program, but is there one for the current method?
salt.racer's user avatar
  • 22.5k
32 votes
4 answers
15k views

Using SFINAE, i can detect wether a given class has a certain member function. But what if i want to test for inherited member functions? The following does not work in VC8 and GCC4 (i.e. detects ...
Georg Fritzsche's user avatar
55 votes
8 answers
15k views

In Ruby I think you can call a method that hasn't been defined and yet capture the name of the method called and do processing of this method at runtime. Can Javascript do the same kind of thing ?
user310291's user avatar
  • 38.7k
181 votes
10 answers
84k views

I want to get into more template meta-programming. I know that SFINAE stands for "substitution failure is not an error." But can someone show me a good use for SFINAE?
rlbond's user avatar
  • 68.5k
42 votes
6 answers
27k views

I'm writing a module in Ruby 1.9.2 that defines several methods. When any of these methods is called, I want each of them to execute a certain statement first. module MyModule def go_forth a re-...
GladstoneKeep's user avatar

15 30 50 per page
1
2 3 4 5
57