Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- template <typename T> struct Box;
- template <typename T, int size> struct Tab;
- template <typename T>
- struct Box {
- T value;
- Box() = default;
- Box(const T& val) : value(val) {}
- };
- template <typename T, int size>
- struct Tab {
- T array[size];
- Tab() {
- for(int i = 0; i < size; i++)
- array[i] = T(i+1);
- }
- T* begin() {
- return array;
- }
- T* end() {
- return array + size;
- }
- };
- template<typename T>
- std::ostream& operator<< (std::ostream& out, const Box<T>& elem) {
- out << elem.value;
- return out;
- }
- template <typename T>
- Box<T> make_Box(const T& val) {
- return Box<T>(val);
- }
- int main() {
- std::cout << Box<int>(23.02) << "\n"; // wypisywany typ to Box<int>
- std::cout << make_Box(23.02) << "\n"; // wypisywany typ to Box<...>
- for(const Box<int>& _ : Tab<Box<int>, 5>())
- std::cout << _ << ", ";
- }
- /*
- 23
- 23.02
- 1, 2, 3, 4, 5,
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement