How to know if a type is a specialization of std::vector?

In C++11 you can also do it in a more generic way: #include <type_traits> #include <iostream> #include <vector> #include <list> template<typename Test, template<typename…> class Ref> struct is_specialization : std::false_type {}; template<template<typename…> class Ref, typename… Args> struct is_specialization<Ref<Args…>, Ref>: std::true_type {}; int main() { typedef std::vector<int> vec; typedef int not_vec; std::cout << is_specialization<vec, std::vector>::value << is_specialization<not_vec, … Read more

What does the tt metavariable type mean in Rust macros?

That’s a notion introduced to ensure that whatever is in a macro invocation correctly matches (), [] and {} pairs. tt will match any single token or any pair of parenthesis/brackets/braces with their content. For example, for the following program: fn main() { println!(“Hello world!”); } The token trees would be: fn main () ∅ … Read more

Automatically setting an enum member’s value to its name

Update: 2017-03-01 In Python 3.6 (and Aenum 2.01) Flag and IntFlag classes have been added; part of that was a new auto() helper that makes this trivially easy: >>> class AutoName(Enum): … def _generate_next_value_(name, start, count, last_values): … return name … >>> class Ordinal(AutoName): … NORTH = auto() … SOUTH = auto() … EAST = … Read more

Valid characters in a python class name

Python 3 Python Language Reference, §2.3, “Identifiers and keywords” The syntax of identifiers in Python is based on the Unicode standard annex UAX-31, with elaboration and changes as defined below; see also PEP 3131 for further details. Within the ASCII range (U+0001..U+007F), the valid characters for identifiers are the same as in Python 2.x: the … Read more