Anubis | 3 Jul 19:29

[Units][Interval] Using both together

Hello all!

First let me congratule Matthias and Steven for the great units library. 
Just recently I have kicked out my own attempt at something like it and 
switched to boost::units.

However I ran into trouble using both boost::units and boost::interval 
because a single int cannot be static casted to a quantity.

So one could either provide a function like:
static boost::units::quantity<Unit,Y> quantity(int aValue) { 
boost::units::quantity<Unit,Y>::from_value(aValue); }

Probably not the best idea as any value would get casted to a quantity 
without notice, therefore totally ruining the concept of from_value.

Or as I have implemented a specific checking policy for boost::interval:

#include <boost/numeric/interval.hpp>
//! The checking policy for boost::interval, if it uses boost::unit
/*!
  Look into boost/numeric/interval/checking.hpp to see other possible base
  checking policies for template parameter Checking
*/
namespace boost { namespace units { namespace interval_support {
template<class T, class Checking = 
boost::numeric::interval_lib::checking_base<T> >
struct checking_base : Checking
  {
    static T empty_lower()
(Continue reading)

Thomas d'Erceville | 3 Jul 18:42

[Interprocess] Mapped file destructor


Hello,

In my code I open a mapped file (previously created) and I construct an object inside, this object is valid and I can use it. But after the mapped_file has been destroyed my object is not valid anymore. It happens just after the call to the destructor of the mapped file.

How can I tell to the Mapped File to do not flush its content when it is destructed?

Best regards.

Thomas
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Alexander Heinrich | 3 Jul 18:20

Re: [smart_ptr] weak_ptr / shared_ptr interaction


Both s1 and s2 should now have use_count of 2 at this point, since there
are 2 shared_ptrs sharing ownership of the same pointee.

The post-condition expression is correct; the value of r.use_count()
was changed by the construction of the new shared_ptr.
Thanks for your reply. So you're saying that the behavior of shared_ptr is correct (perfectly fine with me). But then I have to say, that the documentation of shared_ptr located under
is wrong, because it says that if you construct a shared_ptr from a weak_ptr (!) the use_count will *not* change.
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hicham Mouline | 3 Jul 17:51

detect if a type has a size_t member

Hello

template <typename T>
struct S {
   // how to detect T has a member static const size_t value ?
   // if T has value, define member of S,  m1 of type T1, otherwise m2 of
type T2
};

Regards,
Alexander Heinrich | 3 Jul 13:52

[smart_ptr] weak_ptr / shared_ptr interaction

Hi <at> boost-users.
The documentation of shared_ptr states the following:
<quote>
template<class Y> explicit shared_ptr(weak_ptr<Y> const & r);

Effects: Constructs a shared_ptr that shares ownership with r and stores a copy of the pointer stored in r.

Postconditions: use_count() == r.use_count().
</quote>
Now I experienced some odd behavior with the following piece of code:
<code>
boost::shared_ptr<int> s1(new int(42)); // use_count == 1
boost::weak_ptr<int> w(s1); // use_count == 1
boost::shared_ptr<int> s2(w); // use_count == 2 (expected use_count == 1)
boost::shared_ptr<int> s3 = s2; // use_count == 3 (not sure what to expect here...)
</code>
1) According to the documentation use_count should still be 1 after instantiating s2, but it is 2. Or did I misinterpret the docs?
2) Independent of whether instantiating s2 increments the use_count or not, I am unsure if assigning (or copying) a shared_ptr that was constructed from a weak_ptr should increment the use_count (see s3).
I'd appreciate any comments on this.
Best regards,
Alexander
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
s seelenluft | 3 Jul 12:52

Possible to put path to boost library somewhere else than Jamroot file?

Hi,

my question is whether I can put the path to the boost library in a another file than the Jamroot file (eg, boost-build.jam)?

I run run longish simulations on multiple workstations, essentially Debian and Mac OS X machines. For good or bad reasons, the path to the boost library is differs between machines. I give the path via an <include> in the Jamroot file. Thus the Jamroot file has to be different on each machine.
However, my code is synchronized via Subversion between the machines which poses a problem for the Jamroot file. Thus, I either can only do one-way synchronisation from one master computer and edit the Jamroot file on the other machines locally (marking the conflict as resolved after the first update after this edit) or exclude the Jamroot file from Subversion.  Since I probably do modify the Jamroot file from time to time, it would be nice to include it in Subversion. Currently, I solve the problem by sticking to one-way synchronisation but if there would be another place to put the path, this would be nicer.

Thanks.

Markus

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
christophe henry | 3 Jul 16:38
Favicon

[Proto] Recreating an expression

Thanks Eric for your fast answer!
Unfortunately, this doesn't solve my problem. To make a very very long discussion long, here a small
example showing the problem from another side:
I have an expression wrapper called mp_terminal and I define terminals, but not in the documented
way (which I suspect is the problem) but instead deriving from them (for convenience purposes), for example:
struct True : mp_terminal<typename proto::terminal<guard_tag>::type>
{...}
These terminals are used with a simple grammar:
struct BuildGuards
   : proto::or_<
        proto::when<
                    proto::logical_or<BuildGuards,BuildGuards >,
                    GuardOR<BuildGuards(proto::_left),BuildGuards(proto::_right)>()
                >,
        proto::when<
                    proto::logical_and<BuildGuards,BuildGuards >,
                    GuardAND<BuildGuards(proto::_left),BuildGuards(proto::_right)>()
                >,
        proto::when<
                    proto::logical_not<BuildGuards >,
                    GuardNOT<BuildGuards(proto::_value)>()
                >,
         proto::when <
                    proto::terminal<guard_tag>,
                    proto::_()
  >
   >
{};
Then, expressions like:
True()|| False() give the expected result (struct GuardOR<struct True,struct False>).
Even True()&& (Dummy1() || !(False() || True())) give the expected result:
struct GuardAND<struct True,struct GuardOR<struct Dummy1,struct GuardNOT<struct GuardOR<struct False,struct True> > > >
But a "!" alone (meaning followed by just a terminal, not the other parts of the BuildGuards grammar) breaks all (as do all unary operators I tried), like !False() or True()|| !False().
!False() =>
struct GuardNOT<struct mp_terminal<struct boost::proto::exprns_::expr<struct boost::proto::tag::terminal,struct boost::proto::argsns_::term<struct guard_tag>,0> > >
 
Notice that !(False() || True()) works!
 
Now, if I do not derive from mp_terminal but instead proceed as documented, all works as expected:
proto::terminal<True>::type True_;
...
!False_ => correct result.
Sadly, this documented usage is unpractical in my use case.
So, supposing that I managed this easy grammar, I imagine that the usage I do of terminals (deriving from them) is not allowed.

Then, why do most use cases work like a charm? Only unary operators seem to fail.
 
Attached are 2 test files. V1 doesn't work in all cases while V2 does.
I use 1.38.
 
Thanks a lot!
 
Christophe

Windows Live™: Keep your life in sync. Check it out!
// TestProto.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <boost/proto/core.hpp>
#include <boost/proto/transform.hpp>

using namespace std;
namespace proto = boost::proto;

struct guard_tag{};

// grammar forbidding address of for terminals
struct terminal_grammar : 
		proto::not_<proto::address_of<proto::_> >
{};

// Forward-declare an expression wrapper
template<typename Expr>
struct mp_terminal;

struct sm_domain
	: proto::domain< proto::generator<mp_terminal>, terminal_grammar >
{};

template<typename Expr>
struct mp_terminal
	: proto::extends<Expr, mp_terminal<Expr>, sm_domain>
{
	typedef
		proto::extends<Expr, mp_terminal<Expr>, sm_domain>
		base_type;
	// Needs a constructor
	mp_terminal(Expr const &e = Expr())
		: base_type(e)
	{}
	// Unhide Proto's overloaded assignment operator
	using base_type::operator=;
};

template <class T1,class T2>
struct GuardOR 
{
    template <class FSM,class EVT,class SourceState,class TargetState>
    bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt)
    {
        return (T1()(fsm,evt,src,tgt) || T2()(fsm,evt,src,tgt));
    }
};
template <class T1,class T2>
struct GuardAND 
{
	template <class FSM,class EVT,class SourceState,class TargetState>
	bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt)
	{
		return (T1()(fsm,evt,src,tgt) && T2()(fsm,evt,src,tgt));
	}
};
template <class T1>
struct GuardNOT 
{
	template <class FSM,class EVT,class SourceState,class TargetState>
	bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt)
	{
		return !(T1()(fsm,evt,src,tgt));
	}
};

struct BuildGuards
   : proto::or_<
        proto::when<
                    proto::logical_or<BuildGuards,BuildGuards >,
                    GuardOR<BuildGuards(proto::_left),BuildGuards(proto::_right)>()
                >,
        proto::when<
                    proto::logical_and<BuildGuards,BuildGuards >,
                    GuardAND<BuildGuards(proto::_left),BuildGuards(proto::_right)>()
                >,
        proto::when<
                    proto::logical_not<BuildGuards >,
                    GuardNOT<BuildGuards(proto::_value)>()
                >,
         proto::when <
					proto::terminal<guard_tag>,
                    proto::_()
				>
   >
{};

struct True : mp_terminal<typename proto::terminal<guard_tag>::type>
{
	template <class T>
	bool operator()(T&)
	{
		std::cout << "always true" << std::endl;
		return true;
	}
};
struct False : mp_terminal<typename proto::terminal<guard_tag>::type>
{
	template <class T>
	bool operator()(T& )
	{
		std::cout << "always false" << std::endl;
		return false;
	}
};
struct Dummy1 : mp_terminal<typename proto::terminal<guard_tag>::type>
{
	template <class T>
	bool operator()(T& )
	{
		std::cout << "dummy" << std::endl;
		return true;
	}
};
template <class Expr>
void print_guard(Expr const& expr)
{
	cout << "in print_guard" << endl;
	cout << "matches:" << proto::matches<Expr,BuildGuards>::value << endl;
	typedef
		boost::result_of<BuildGuards(Expr)>::type
		result_type;
	cout << "result_type" << endl;
	cout << typeid(result_type).name() << endl;

	cout << "end print_guard" << endl;
}

int main()
{
	print_guard((True()&& Dummy1()));
	print_guard((True()|| False()));
	print_guard( ( True()&& (Dummy1() || !(False() || True())) ) );
	print_guard((True()|| !False()));
	print_guard( (!False()) );
    return 0;
}

// TestProto.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <boost/proto/core.hpp>
#include <boost/proto/transform.hpp>


using namespace std;
namespace proto = boost::proto;

struct guard_tag{};

// grammar forbidding address of for terminals
struct terminal_grammar : 
		proto::not_<proto::address_of<proto::_> >
{};

// Forward-declare an expression wrapper
template<typename Expr>
struct mp_terminal;

struct sm_domain
	: proto::domain< proto::generator<mp_terminal>, terminal_grammar >
{};

template<typename Expr>
struct mp_terminal
	: proto::extends<Expr, mp_terminal<Expr>, sm_domain>
{
	typedef
		proto::extends<Expr, mp_terminal<Expr>, sm_domain>
		base_type;
	// Needs a constructor
	mp_terminal(Expr const &e = Expr())
		: base_type(e)
	{}
	// Unhide Proto's overloaded assignment operator
	using base_type::operator=;
};

template <class T1,class T2>
struct GuardOR 
{
    template <class FSM,class EVT,class SourceState,class TargetState>
    bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt)
    {
        return (T1()(fsm,evt,src,tgt) || T2()(fsm,evt,src,tgt));
    }
};
template <class T1,class T2>
struct GuardAND 
{
	template <class FSM,class EVT,class SourceState,class TargetState>
	bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt)
	{
		return (T1()(fsm,evt,src,tgt) && T2()(fsm,evt,src,tgt));
	}
};
template <class T1>
struct GuardNOT 
{
	template <class FSM,class EVT,class SourceState,class TargetState>
	bool operator()(FSM& fsm,EVT const& evt,SourceState& src,TargetState& tgt)
	{
		return !(T1()(fsm,evt,src,tgt));
	}
};
struct BuildGuards
   : proto::or_<
        proto::when<
                    proto::logical_or<BuildGuards,BuildGuards >,
                    GuardOR<BuildGuards(proto::_left),BuildGuards(proto::_right)>()
                >,
        proto::when<
                    proto::logical_and<BuildGuards,BuildGuards >,
                    GuardAND<BuildGuards(proto::_left),BuildGuards(proto::_right)>()
                >,
        proto::when<
                    proto::logical_not<BuildGuards >,
                    GuardNOT<BuildGuards(proto::_value)>()
                >,
         proto::when <
					proto::terminal<proto::_>,
					proto::result_of::value<proto::_>()
				>
   >
{};

struct True
{
	template <class T>
	bool operator()(T&)
	{
		std::cout << "always true" << std::endl;
		return true;
	}
};
struct False
{
	template <class T>
	bool operator()(T& )
	{
		std::cout << "always false" << std::endl;
		return false;
	}
};
struct Dummy1
{
	template <class T>
	bool operator()(T& )
	{
		std::cout << "dummy" << std::endl;
		return true;
	}
};
template <class Expr>
void print_guard(Expr const& expr)
{
	cout << "in print_guard" << endl;
	cout << "matches:" << proto::matches<Expr,BuildGuards>::value << endl;
	typedef
		boost::result_of<BuildGuards(Expr)>::type
		result_type;
	cout << "result_type" << endl;
	cout << typeid(result_type).name() << endl;

	cout << "end print_guard" << endl;
}

int main()
{
	proto::terminal<True>::type True_;
	proto::terminal<False>::type False_;
	proto::terminal<Dummy1>::type Dummy1_;

	print_guard((True_&& Dummy1_));
	print_guard((True_|| False_));
	print_guard( ( True_&& (Dummy1_ || !(False_ || True_)) ) );
	print_guard((True_|| !False_));
	print_guard( (!False_) );
    return 0;
}

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Commander Pirx | 3 Jul 16:17
Favicon

[Spirit] chset_p

Hi all,

I've detected a strange behavior of Spirit using (VC9SP1). I assume that

chset_p( "-_!#$%&*+|~" ) and
chset_p( "!#$%&*+-_|~" )

are identical. I've only changed the order of the characters a little bit. 
But when i'm trying to parse a string like "abcd-edfg: " the parser eats the 
':' sign but shouldn't. Examples here:

   token_  = alnum_p | chset_p( "-_!#$%&*+|~" );

//    the line above works fine

   token_ = alnum_p | chset_p( "!#$%&*+-_|~" );

//    here the ':' sign will be consumed!

Thanx. 
Ivan Gonzalez | 3 Jul 10:19

Using iostreams to serialize into and from a memory buffer

Dear all,


I have some numerical data in my code that I'm saving to a file. My code loops thousands of times generating a set of this data in each loop step. The data is reused within the same step but there is no need to save it to the next one. Currently I'm using the serialization library to write all the data to a binary file (using the optimization for contiguous arrays) and then read it. I thought (maybe naively) I could increase performance keeping the data in memory instead of write/read to disk. I came across this post http://lists.boost.org/boost-users/2008/05/36235.php where how to serialize into/from a memory buffer using boost::iostreams is explained. However I found that using the solution in the post is way slower than write/read to disk. In fact modifying the code in the post to use std::ofstream and std::ifstream open with the std::ios::binary flag makes the code 5 times faster.

Am I missing something or is it right that the iostream solution is slower ?.  (I understand that sometimes you don't have the option to write to a file, but is this the fastest way to use a memory buffer ?)

Thanks in advance,

Ivan 


_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
梁绍池 | 3 Jul 03:38

[Range.Ex / String.Algo] Ambiguous call to overload function "find"

I use vc 9.0 to compile the following code with boost 1.39.0 and range_ex.


    #include<string>
    #include<boost/algorithm/string.hpp>
    #include<boost/range/algorithm.hpp>

    int main() {
        std::string s = "hello";
        boost::find_first(s, "lo");
        return 0;
    }

The compiler will complain ambiguous call to overload function "find". I found there's also a "find" in boost/range/algorithm.hpp. Even worse when I change the type of "s" to const std::string, the compiler will resolute "find" call as the one in boost/range/algorithm.hpp
and reports an error "const_iterator is not a member of std::_String_const_iterator". Now I just indicated the "find" call in boost::find_first explicitly. Is there a better way to solve it?

Thanks!
S.C. Leung
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ryan McConnehey | 3 Jul 03:29

One common mutex and lock to rule them all

Are there plans to provide a command mutex and lock? 

I know there are versions in both the thread and interprocess library.  
I'm sure each library developed their own as the library was being 
created.  I've seen users ask about different mutexes and lock before 
and usually they are directed  to either of these libraries.  It would 
seem, from a user perspective, that a more central location for mutexes 
and lock would be helpful.  Possibly in it's own header library.  Is 
there a plan to do this in the future?

Ryan

Gmane