-
-
Save komori-n/086c8d369fbfde0f06e947696c6d11ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <utility> | |
template <typename T> | |
struct Hoge { | |
template <typename U=T> | |
auto func(void) | |
-> std::enable_if_t<std::is_same<U, void>::value, void> { | |
std::cout << "void" << std::endl; | |
} | |
template <typename U=T> | |
auto func(void) | |
-> std::enable_if_t<!std::is_same<U, void>::value, void> { | |
std::cout << "not void" << std::endl; | |
} | |
}; | |
int main(int argc, char* argv[]) { | |
Hoge<int>().func(); | |
Hoge<void>().func(); | |
Hoge<void>().func<int>(); // not void | |
return EXIT_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <utility> | |
template <typename T> | |
struct Hoge { | |
template <bool AlwaysTrue = true> | |
auto func(void) | |
-> std::enable_if_t<std::is_same<T, void>::value && AlwaysTrue, void> { | |
std::cout << "void" << std::endl; | |
} | |
template <bool AlwaysTrue = true> | |
auto func(void) | |
-> std::enable_if_t<!std::is_same<T, void>::value && AlwaysTrue, void> { | |
std::cout << "not void" << std::endl; | |
} | |
}; | |
int main(int argc, char* argv[]) { | |
Hoge<int>().func(); | |
Hoge<void>().func(); | |
// error! | |
// Hoge<void>().func<false>(); | |
return EXIT_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <utility> | |
template <typename T> | |
struct Hoge { | |
template <std::nullptr_t Dummy = nullptr> | |
auto func(void) | |
-> std::enable_if_t<std::is_same<T, void>::value && Dummy == nullptr, void> { | |
std::cout << "void" << std::endl; | |
} | |
template <std::nullptr_t Dummy = nullptr> | |
auto func(void) | |
-> std::enable_if_t<!std::is_same<T, void>::value && Dummy == nullptr, void> { | |
std::cout << "not void" << std::endl; | |
} | |
}; | |
int main(int argc, char* argv[]) { | |
Hoge<int>().func(); | |
Hoge<void>().func(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment