Following is clipped version of what I am trying to achive. I am doing some bit arithmatic on a word, I would like to use __builtin_clrsb when it is available and the user uses int as the word type else compile with slow algorithm. Following compiles with __builtin_clrsb regardless of the WORD type.
Code uses C++11 but runs on an embedded system so I do not have access to most of std:: facilities.
#if !defined(WORD)
#define WORD int
#endif
template<size_t S, typename word = WORD>
class my_class {
...
...
...
size_t do_stuff(){
#if WORD == int && defined(__builtin_clrsb)
//compile with __builtin_clrsb
#else
//comple with slow method
#endif
}
};
Aucun commentaire:
Enregistrer un commentaire