Not Enough Math
Lightweight zero-dependency C++ math library
Loading...
Searching...
No Matches
vec_io.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <string>
5#include <sstream>
6
7#include "vec.hpp"
8
9namespace nem
10{
11 static constexpr const char* VECTOR_SEPARATOR = ", ";
12 static constexpr const char* VECTOR_L_BRACE = "(";
13 static constexpr const char* VECTOR_R_BRACE = ")";
14
15 template<typename T, size_t N>
16 std::ostream& operator<<(std::ostream& os, const nem::vec<T, N>& vec)
17 {
18 os << VECTOR_L_BRACE;
19 for (size_t i = 0; i < N; ++i)
20 {
21 os << vec[i] << (i < N - 1 ? VECTOR_SEPARATOR : "");
22 }
23 os << VECTOR_R_BRACE;
24 return os;
25 }
26
27 template<typename T, size_t N>
28 std::istream& operator>>(std::istream& is, nem::vec<T, N>& vec)
29 {
30 for (size_t i = 0; i < N; ++i)
31 {
32 is >> vec[i];
33 }
34 return is;
35 }
36
37 template<typename T, size_t N>
38 std::string tostr(const nem::vec<T, N>& vec)
39 {
40 std::stringstream ss;
41 ss << VECTOR_L_BRACE;
42 for (size_t i = 0; i < N; ++i)
43 {
44 ss << vec[i] << (i < N - 1 ? VECTOR_SEPARATOR : "");
45 }
46 ss << VECTOR_R_BRACE;
47 return ss.str();
48 }
49}
Definition config.hpp:16
static constexpr const char * VECTOR_R_BRACE
Definition vec_io.hpp:13
static constexpr const char * VECTOR_L_BRACE
Definition vec_io.hpp:12
std::istream & operator>>(std::istream &is, mat< T, C, R > &matrix)
Definition mat_io.hpp:48
static constexpr const char * VECTOR_SEPARATOR
Definition vec_io.hpp:11
std::ostream & operator<<(std::ostream &os, const mat< T, C, R > &matrix)
Definition mat_io.hpp:32
std::string tostr(const mat< T, C, R > &matrix)
Definition mat_io.hpp:15