Overloading versus template specialization to determine behaviour

When using templates to determine the behaviour of a function or class (e.g. if you test type traits), is there any particular disadvantages and/or advantages to using either overloading or template specialization? (Forgive me, I didn't really know how to phrase my question.)

For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <type_traits>

//Overloading
void funky(std::true_type);
void funky(std::false_type);

//Template specialization
template <typename TypeCondition>
    void baz();

template <>
    void baz<std::true_type>();
template <>
    void baz<std::false_type>();

//...

int main(){

    funky(std::is_foo<int>::type()); //Choose behaviour based on overloading

    baz<std::is_foo<int>::type>(); //Choose behaviour based on template specialization
}
Last edited on
Topic archived. No new replies allowed.