Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is this a bad practice?

const int sId(int const id);

// true/false it doesn't matter
template<bool i>
const int sId(int const id) {
    return this->id = id;

const int MCard::sId(int const id){
    MCard card = *this;

    this->id = id;

    this-><MCard&, MCard&>(*this, card));

    return this->id;



As you can see, my goal is to be able to have an alternative behaviour for sId.
I know I could use a second parameter to the function and use a if, but this feels more fun (imo) and might prevent branch prediction (I'm no expert in that field).

So, is it a valid practice, and/or is there a better approach?

share|improve this question
This would warrant a WTF moment in code review for me. I see what you're going for, and I sympathize your cause. That said, don't do it. – Neil Jun 9 '14 at 10:26
Why not just two functions: sId() and sIdTrue() – Loki Astari Jun 10 '14 at 3:50
up vote 10 down vote accepted

Actually, it seems you are just overcomplicating things, which might obfuscate your code. This


and this


are just two different functions. And the standard way of implementing two different functions (with the same signature) is simply to use two different function names, without the template hoodoo voodoo, like sIdWithoutEvent and sId (assumed the latter one is calling the event).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.