Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoklavat committed Mar 18, 2021
1 parent e609f22 commit ea79350
Show file tree
Hide file tree
Showing 4 changed files with 1,074 additions and 1,017 deletions.
24 changes: 24 additions & 0 deletions 63-DefaultFunctionTemplateArguments.cpp
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;
}
27 changes: 27 additions & 0 deletions 64-TemplateSpecialization.cpp
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;
}
Loading

0 comments on commit ea79350

Please sign in to comment.