boost-optional

Can't see boost::optional contents when debugging with Visual Studio

邮差的信 提交于 2019-12-10 03:02:21
问题 If I try to look at the variable directly, I see a ? sign. If I create a watch calling the is_initialized function, I get the following error: CXX0033: Error: error in OMF type information I didn't find much info about this error related to Boost using Google. Anybody else experienced this? It's a hassle using OutputDebugString everywhere and rebuilding... EDIT : Using Visual Studio 2010 SP1 with all hotfixes in Windows XP SP3 idem, and Boost 1.49.0 UPDATE : This issue comes and goes, it

boost::optional alternative in C++ Standard Library

给你一囗甜甜゛ 提交于 2019-12-08 23:37:49
问题 I'm trying to get my program working without boost usage, but can't find an alternative of some useful patterns. Namely, I can't find boost::optional -likewise pattern in the standard library. Is there some standard alternative for boost::optional (C++11 or somewhere else)? 回答1: Short answer: No. Long answer: Roll your own according to the boost spec. The documentation is quite exhaustive and the code isn't that complex, but this still requires above average C++ skills. To update this answer:

Use boost::optional together with boost::adaptors::indirected

▼魔方 西西 提交于 2019-12-08 17:31:16
问题 I am trying to compile the following code: #include <iostream> #include <iterator> #include <vector> #include <boost/assign/std/vector.hpp> #include <boost/optional.hpp> #include <boost/range/adaptor/indirected.hpp> #include <boost/range/algorithm/copy.hpp> int main( int argc, char ** argv ) { using namespace boost::assign; using boost::adaptors::indirected; std::vector<boost::optional<unsigned> > values; values += 1u,2u,3u; boost::copy( values | indirected, std::ostream_iterator<unsigned>(

init boost::optional of non-copyable object

淺唱寂寞╮ 提交于 2019-12-06 19:22:53
问题 What should I do to initialize boost::optional< T > if underlying type T is non-default constructible, non-copyable/moveable, but one's instance still can exist? Is it forbidden for boost::optional by any semantic reasons to have some member function like template< typename... Args > boost::optional< T >::construct(Args && ...args) , that delivers all the arguments to in-place operator new to construct the object entirely (for non-ref type T )? Variant is to have non-member function like std:

Conversion of boost::optional to bool

好久不见. 提交于 2019-12-06 18:08:15
问题 How I can prevent the last line of this code from compiling? #include <boost/optional.hpp> int main() { typedef boost::optional<int> int_opt; int_opt opt = 0; bool x = opt; // <- I do not want this to compile } The last line doesn't examine opt 's contained int value, but instead compiles as a type conversion to bool, and doesn't seem to be what the user intended. The safe bool idiom seems to be relevant here? 回答1: The whole point of boost::optional is to enable code like this: void func

How to disengage std::experimental::optional?

女生的网名这么多〃 提交于 2019-12-05 10:44:00
With Boost I can create an optional in-place with: boost::optional<boost::asio::io_service::work> work = boost::in_place(boost::ref(io_service)); And disengage it with: work = boost::none; With C++14 / experimental support, I can instead construct an optional in-place with: std::experimental::optional<boost::asio::io_service::work> work; work.emplace(boost::asio::io_service::work(io_service)); But I'm at a loss for how to disengage it... work = std::experimental::nullopt; should disengage work . The library fundamental TS specifies in [optional.nullopt]: The struct nullopt_t is an empty

boost::optional not letting me reassign const value types

让人想犯罪 __ 提交于 2019-12-05 08:20:05
It seems to me there should be four variants of boost::optional optional<Foo> => holds a mutable Foo and can be reassigned after initialization optional<Foo const> const => holds a const Foo and can't be reassigned after initialization optional<Foo> const => (should?) hold a mutable Foo but can't be reassigned after initialization optional<Foo const> => (should?) hold a const Foo and can be reassigned after initialization The first 2 cases work as expected. But the optional<Foo> const dereferences to a const Foo, and the optional<Foo const> doesn't allow reassignment after initialization (as

init boost::optional of non-copyable object

浪尽此生 提交于 2019-12-05 02:04:01
What should I do to initialize boost::optional< T > if underlying type T is non-default constructible, non-copyable/moveable, but one's instance still can exist? Is it forbidden for boost::optional by any semantic reasons to have some member function like template< typename... Args > boost::optional< T >::construct(Args && ...args) , that delivers all the arguments to in-place operator new to construct the object entirely (for non-ref type T )? Variant is to have non-member function like std::make_shared< T > . It seems to me, that my problem can be solved by means of using of std::unique_ptr

Conversion of boost::optional to bool

◇◆丶佛笑我妖孽 提交于 2019-12-05 01:11:07
How I can prevent the last line of this code from compiling? #include <boost/optional.hpp> int main() { typedef boost::optional<int> int_opt; int_opt opt = 0; bool x = opt; // <- I do not want this to compile } The last line doesn't examine opt 's contained int value, but instead compiles as a type conversion to bool, and doesn't seem to be what the user intended. The safe bool idiom seems to be relevant here? The whole point of boost::optional is to enable code like this: void func(boost::optional<int> optionalArg) { if (optionalArg) { doSomething(*optionalArg); } } So the implicit conversion

Viewing a raw pointer as a range in range-based for-loop

懵懂的女人 提交于 2019-12-04 04:21:32
问题 How can I make a raw pointer behave like a range, for a for-range loop syntax. double five = 5; double* dptr = &five; for(int& d : dptr) std::cout << d << std::endl;// will not execute if the pointer is null Motivation: It is now vox populi that an boost::optional (future std::optional ) value can be viewed as a range and therefore used in a for range loop http://faithandbrave.hateblo.jp/entry/2015/01/29/173613. When I rewrote my own simplified version of it: namespace boost { template <class