Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <array>
- #include <set>
- #include <type_traits>
- template <typename Container, typename = typename std::enable_if_t<std::is_same_v<typename Container::value_type, int>>>
- std::string toString(const Container &c, char delimiter = ' ')
- {
- std::string res;
- for (auto ele : c)
- {
- res += std::to_string(ele) + " " + delimiter;
- }
- if (!res.empty())
- {
- res.pop_back();
- }
- return res;
- }
- int main()
- {
- std::vector<int> vec{1, 2, 3};
- std::array<int, 3> arr{1, 2, 3};
- std::set<int> set{1, 2, 3};
- std::cout << toString(vec) << std::endl;
- std::cout << toString(arr) << std::endl;
- std::cout << toString(set) << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement