X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=boost%2Frandom%2Fdetail%2Fvector_io.hpp;fp=boost%2Frandom%2Fdetail%2Fvector_io.hpp;h=0bb261c3ae23f3709a39ad3d2835d0a80ad005b0;hp=0000000000000000000000000000000000000000;hb=2d71eb92104693ca9baa5a2e1c23eeca776d8fd3;hpb=da57529b92adbb7ae74a89861cb39fb35ac7c62d diff --git a/boost/random/detail/vector_io.hpp b/boost/random/detail/vector_io.hpp new file mode 100644 index 0000000..0bb261c --- /dev/null +++ b/boost/random/detail/vector_io.hpp @@ -0,0 +1,75 @@ +/* boost random/vector_io.hpp header file + * + * Copyright Steven Watanabe 2011 + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * See http://www.boost.org for most recent version including documentation. + * + * $Id: vector_io.hpp 71018 2011-04-05 21:27:52Z steven_watanabe $ + */ + +#ifndef BOOST_RANDOM_DETAIL_VECTOR_IO_HPP +#define BOOST_RANDOM_DETAIL_VECTOR_IO_HPP + +#include +#include +#include + +namespace boost { +namespace random { +namespace detail { + +template +void print_vector(std::basic_ostream& os, + const std::vector& vec) +{ + typename std::vector::const_iterator + iter = vec.begin(), + end = vec.end(); + os << os.widen('['); + if(iter != end) { + os << *iter; + ++iter; + for(; iter != end; ++iter) + { + os << os.widen(' ') << *iter; + } + } + os << os.widen(']'); +} + +template +void read_vector(std::basic_istream& is, std::vector& vec) +{ + CharT ch; + if(!(is >> ch)) { + return; + } + if(ch != is.widen('[')) { + is.putback(ch); + is.setstate(std::ios_base::failbit); + return; + } + T val; + while(is >> std::ws >> val) { + vec.push_back(val); + } + if(is.fail()) { + is.clear(); + if(!(is >> ch)) { + return; + } + if(ch != is.widen(']')) { + is.putback(ch); + is.setstate(std::ios_base::failbit); + } + } +} + +} +} +} + +#endif // BOOST_RANDOM_DETAIL_VECTOR_IO_HPP