Using boost parse datetime string: With single digit hour format

I’ll leave it to you to sort out how you want dates without years to be interpreted. However, here’s a quick start using /just/ strptime. I used it in a larger codebase, and we needed some pretty versatile date recognition. Behold: the adaptive datetime parser: #pragma once #include <string> #include <chrono> #include <cstdint> #include <list> … Read more

When must you pass io_context to boost::asio::spawn? (C++)

Asio has added the concept of associated executors and default executors. The associated executors is not really new, because the handler_invoke protocol already allowed for handler-type specific semantics. However, since the formulation of the executor concept it became more generalized. Now you can post any handler, and it will execute on the associated executor, the … Read more

How to parse csv using boost::spirit

For a background on parsing (optionally) quoted delimited fields, including different quoting characters (‘, “), see here: Parse quoted strings with boost::spirit For a very, very, very complete example complete with support for partially quoted values and a splitInto(input, output, ‘ ‘); method that takes ‘arbitrary’ output containers and delimiter expressions, see here: How to … Read more

How to serialize derived template classes with Boost.serialize?

First tell boost that Feature is abstract, is not always needed: BOOST_SERIALIZATION_ASSUME_ABSTRACT(Feature); The serialization method should look more or less like this: template<class Archive> void Feature::serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(some_member); } template<typename T,class Archive> void GenericFeature<T>::serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::base_object<Feature>(*this); //serialize base class … Read more

Efficiently reading a very large text file in C++

I’d redesign this to act streaming, instead of on a block. A simpler approach would be: std::ifstream ifs(“input.txt”); std::vector<uint64_t> parsed(std::istream_iterator<uint64_t>(ifs), {}); If you know roughly how many values are expected, using std::vector::reserve up front could speed it up further. Alternatively you can use a memory mapped file and iterate over the character sequence. How to … Read more

Building boost with Visual Studio 2013 (Express)

I’ve recently built Boost on MSVC12 (VS2013) using only a minor patch: Subject: [PATCH] Fixing boost serialization build on MSVC2013 include fix (manual) config_decltype_n3276_new.patch (from https://svn.boost.org/trac/boost/ticket/9410) As you can see it combines the patch from https://svn.boost.org/trac/boost/ticket/9410 with some manual include fixes (they were trivial). This is the effective patch: diff –git a/3rdparty/boost_1_55_0/boost/archive/iterators/transform_width.hpp b/3rdparty/boost_1_55_0/boost/archive/iterators/transform_width.hpp index 5a5c7b7..8da85ee … Read more

How to build Boost 1.64 in 64 bits?

To update the answer I gave here. Visual Studio 2017 is a new toolset, so simply replace toolset=msvc-14.0 (for Visual Studio 2015) with toolset=msvc-14.1 i.e.: In a Visual Studio tools Command Prompt: cd boost_1_64_0 call bootstrap.bat For static libraries (recommended for Windows): b2 -j8 toolset=msvc-14.1 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared –build-type=complete stage Note: thread must … Read more

How to print boost::any to a stream?

You could use boost::spirit::hold_any instead. It’s defined here: #include <boost/spirit/home/support/detail/hold_any.hpp> and is fully compatible with boost::any. This class has two differences if compared to boost::any: it utilizes the small object optimization idiom and a couple of other optimization tricks, making spirit::hold_any smaller and faster than boost::any it has the streaming operators (operator<<() and operator>>()) defined, … Read more