NDArrayHelper.h
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <vector>
4
5#include <SimoxUtility/algorithm/string.h>
6
8{
9public:
10 // Uses the simox utility to parse floatingpoint and fixed precision types
11 // it then writes the result into a byte vector
12 // an empty byte vector encodes a parsing error.
13 template <typename T>
14 std::vector<unsigned char> static toByteVector(const std::string& str)
15 {
16 try
17 {
18 auto val = simox::alg::to_<T>(str);
19 std::vector<unsigned char> res(sizeof(val), 0);
20 T* reinterpPtr = reinterpret_cast<T*>(res.data());
21 T* laundered = std::launder(reinterpPtr);
22 *laundered = val;
23 return res;
24 }
25 catch (const simox::error::SimoxError& err)
26 {
27 return {};
28 }
29 }
30};
std::string str(const T &t)
static std::vector< unsigned char > toByteVector(const std::string &str)