-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
1,074 additions
and
1,017 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//63-DefaultFunctionTemplateArguments | ||
|
||
#include <iostream> | ||
#include <iomanip> | ||
|
||
template<typename Target=std::string, typename Source=std::string> | ||
Target to(Source arg){ | ||
std::stringstream interpreter; | ||
Target result; | ||
|
||
if(!(interpreter<<arg) || !(interpreter>>result) || !(interpreter>>std::ws).eof()) | ||
throw std::runtime_error{"to<>() failed"}; | ||
|
||
return result; | ||
} | ||
|
||
int main(){ | ||
auto x1 = to<std::string, double>(1.2); | ||
auto x2 = to<std::string>(1.2); | ||
auto x3 = to<>(1.2); | ||
auto x4 = to(1.2); | ||
|
||
std::cout << x1 << ", " << x2 << ", " << x3 << ", " << x4 << std::endl; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//64-TemplateSpecialization | ||
|
||
#include <iostream> | ||
|
||
template<typename T> | ||
class A{ | ||
public: | ||
A(){std::cout << "Primary specialization." << std::endl;} | ||
}; | ||
|
||
template<typename T> | ||
class A<T*>{ | ||
public: | ||
A(){std::cout << "Pointer specialization." << std::endl;} | ||
}; | ||
|
||
template<> | ||
class A<void*>{ | ||
public: | ||
A(){std::cout << "Void specialization." << std::endl;} | ||
}; | ||
|
||
int main(){ | ||
A<int> a1; | ||
A<int*> a2; | ||
A<void*> a3; | ||
} |
Oops, something went wrong.