generated from brenozd/python-template
refactor: remove templated sample file
• Deleted templated_sample.cpp • This file contained an example template usage and is no longer needed.
This commit is contained in:
@@ -1,31 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
template <typename T> T add_values(const T &a, const T &b) { return a + b; }
|
|
||||||
|
|
||||||
template <typename T> class Box {
|
|
||||||
public:
|
|
||||||
explicit Box(const T &value) : value_(value) {}
|
|
||||||
const T &get() const { return value_; }
|
|
||||||
const T *get_2() const { return value_; }
|
|
||||||
void set(const T &v) { value_ = v; }
|
|
||||||
template <typename U> U convert_to() const { return static_cast<U>(value_); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
T value_;
|
|
||||||
};
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Box<int> ibox(42);
|
|
||||||
std::cout << "Box<int>: " << ibox.get() << "\n";
|
|
||||||
|
|
||||||
Box<double> dbox(3.14);
|
|
||||||
std::cout << "Convert double box to int: " << dbox.convert_to<int>() << "\n";
|
|
||||||
|
|
||||||
std::cout << "add_values<int>(2, 3): " << add_values<int>(2, 3) << "\n";
|
|
||||||
|
|
||||||
std::cout << "add_values<std::string>(\"Hello, \", \"World\"): "
|
|
||||||
<< add_values<std::string>("Hello, ", "World") << "\n";
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user