NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
fromstring.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <sstream>
31#include <string_view>
32
33#include "NumCpp/NdArray.hpp"
34
35namespace nc
36{
37 //============================================================================
38 // Method Description:
47 template<typename dtype>
48 NdArray<dtype> fromstring(const std::string& inStr, const char inSep = ' ')
49 {
51
52 std::istringstream inputStream(inStr);
53 auto values = std::vector<dtype>{};
54 dtype value{};
55 for (std::string segment; std::getline(inputStream, segment, inSep);)
56 {
57 if (!inputStream.fail())
58 {
59 std::istringstream segmentStream(segment);
60 while (segmentStream >> value)
61 {
62 if (!inputStream.fail())
63 {
64 values.push_back(value);
65 }
66 }
67 }
68 }
69
70 return NdArray<dtype>(values);
71 }
72} // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
Definition: Cartesian.hpp:40
NdArray< dtype > fromstring(const std::string &inStr, const char inSep=' ')
Definition: fromstring.hpp:48