Search Results

Search found 2 results on 1 pages for 'duli'.

Page 1/1 | 1 

  • C++ "if then else" template substitution

    - by duli
    I would like to declare a template as follows: template <typename T> { if objects of class T have method foo(), then const int k=1 else if class has a static const int L then const int k=L else const int k=0; } How can I do this? In general, I would like a mechanism for setting static consts based on properties of T (or typedef defined inside T).

    Read the article

  • C++ traits question

    - by duli
    I have a templated class template <typename Data> class C { ..... } In most situations, I depend on the compiler to let me substitute types for Data. I call methods foo(), goo() on objects of type Data, so what I substitute needs to provide that. I now need to substitute int and string for my Data type. I do not want to specialize because the class is already too big and would require specializing each method (with only small code change). My options (please tell me if there are more) 1) I can provide wrapper classes around int and string which implement the methods foo(), goo() etc 2) provide a traits class traits that calls foo() or goo() on objects of classes that provide foo(),goo() (these are my present substitutable classes) and specialize these classes for int and string. Questions 1) what are the relative merits of 1 vs 2? 2) My traits classes will have static methods. Can a traits class have non-static methods as well? I see most traits classes define constants in the STL. 3) Do I make the traits classes global or should I pass them in as a template parameter for class C?

    Read the article

1