Skip to content

Instantly share code, notes, and snippets.

@jimwwalker
Last active October 19, 2016 09:30
Show Gist options
  • Save jimwwalker/379002dfaa7b66031fcf21f25236e716 to your computer and use it in GitHub Desktop.
Save jimwwalker/379002dfaa7b66031fcf21f25236e716 to your computer and use it in GitHub Desktop.
type_traits
#include <type_traits>
#include <stdio.h>
#include <string>
#include <cstdint>
class Jim {
public:
bool add(std::string str, bool stuff) {
printf("MADE IT %s\n", str.c_str());
return true;
}
bool add(uint16_t value) {
printf("uint16_t %d\n", value);
return add("add16", true);
}
bool add(uint32_t value) {
printf("uint32_t %d\n", value);
return add("add32", true);
}
template <typename T>
typename std::enable_if<std::is_signed<T>::value, bool>::type add(T value) {
printf("template\n");
return add(static_cast< typename std::make_unsigned<T>::type >(value));
}
};
int main() {
Jim j;
int16_t jim1 = 16;
int32_t jim2 = 32;
j.add(jim1);
j.add(jim2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment