Zachary Turner | 1 Jul 03:29
Picon

boost::bind with references

I have a function defined as

template<typename T>
void foo(const T& x);

and then I use boost::bind(foo, x);

However, once the code is inside the body of foo, the addresses of x
inside foo and the addresses of x when I called bind are different.
So somehow a copy is being made.  I can get around it by using
boost::ref(), but is there a technical reason why it doesn't "just
work" and pass it by reference?
Steven Watanabe | 1 Jul 03:57
Picon

Re: boost::bind with references

AMDG

Zachary Turner wrote:
> I have a function defined as
>
> template<typename T>
> void foo(const T& x);
>
> and then I use boost::bind(foo, x);
>
> However, once the code is inside the body of foo, the addresses of x
> inside foo and the addresses of x when I called bind are different.
> So somehow a copy is being made.  I can get around it by using
> boost::ref(), but is there a technical reason why it doesn't "just
> work" and pass it by reference

Capturing by reference is more dangerous because
it can leave dangling references.

In Christ,
Steven Watanabe
Scott McMurray | 1 Jul 04:02
Picon

Re: boost::bind with references

2009/6/30 Zachary Turner <divisortheory <at> gmail.com>:
>
> However, once the code is inside the body of foo, the addresses of x
> inside foo and the addresses of x when I called bind are different.
> So somehow a copy is being made.  I can get around it by using
> boost::ref(), but is there a technical reason why it doesn't "just
> work" and pass it by reference?
>

Well there's no way to tell that it's a reference, so it has to pick
one or the other.  Presumably it chose by-value for default to match
function argument passing.
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Zachary Turner | 1 Jul 04:08
Picon

Re: boost::bind with references

On Tue, Jun 30, 2009 at 8:57 PM, Steven Watanabe<watanabesj <at> gmail.com> wrote:
> AMDG
>
> Zachary Turner wrote:
>>
>> I have a function defined as
>>
>> template<typename T>
>> void foo(const T& x);
>>
>> and then I use boost::bind(foo, x);
>>
>> However, once the code is inside the body of foo, the addresses of x
>> inside foo and the addresses of x when I called bind are different.
>> So somehow a copy is being made.  I can get around it by using
>> boost::ref(), but is there a technical reason why it doesn't "just
>> work" and pass it by reference
>
> Capturing by reference is more dangerous because
> it can leave dangling references.
>

Well, but what I mean is, shouldn't it pass it exactly according to
how the function is specified?  Or maybe there's just no way to do
this.  If the function is specified as taking a T& then I would expect
it to pass by reference, whereas if the function is specified as
taking a T, then I would expect it to pass by value.  Currently it's
passing by value even if the function is expecting a reference, which
will almost never be the programmer's intention, and can introduce
slicing among other things.  Am I missing something?
(Continue reading)

Steven Watanabe | 1 Jul 04:23
Picon

Re: boost::bind with references

AMDG

Zachary Turner wrote:
> On Tue, Jun 30, 2009 at 8:57 PM, Steven Watanabe<watanabesj <at> gmail.com> wrote:
>   
>> AMDG
>>
>> Zachary Turner wrote:
>>     
>>> I have a function defined as
>>>
>>> template<typename T>
>>> void foo(const T& x);
>>>
>>> and then I use boost::bind(foo, x);
>>>
>>> However, once the code is inside the body of foo, the addresses of x
>>> inside foo and the addresses of x when I called bind are different.
>>> So somehow a copy is being made.  I can get around it by using
>>> boost::ref(), but is there a technical reason why it doesn't "just
>>> work" and pass it by reference
>>>       
>> Capturing by reference is more dangerous because
>> it can leave dangling references.
>>
>>     
>
> Well, but what I mean is, shouldn't it pass it exactly according to
> how the function is specified?  Or maybe there's just no way to do
> this.  If the function is specified as taking a T& then I would expect
(Continue reading)

MeMooMeM | 1 Jul 04:18
Picon

Default table size of unordered map


Hi,

What is the default table size of unordered maps in boost? I am trying to
figure out how scalable this function is. My guess is that boost assumes a
default initial table length. If it is exceeded, it needs to re-create
hashes for all entries to grow it, which is costly. I would like to find
that threshold... 

Thanks so much!

--

-- 
View this message in context: http://www.nabble.com/Default-table-size-of-unordered-map-tp24283133p24283133.html
Sent from the Boost - Users mailing list archive at Nabble.com.
Dominique Devienne | 1 Jul 04:35
Picon
Gravatar

Re: Default table size of unordered map

On Tue, Jun 30, 2009 at 9:18 PM, MeMooMeM<mbelgin <at> gmail.com> wrote:
> What is the default table size of unordered maps in boost? I am trying to
> figure out how scalable this function is. My guess is that boost assumes a
> default initial table length. If it is exceeded, it needs to re-create
> hashes for all entries to grow it, which is costly. I would like to find
> that threshold...
>
> Thanks so much!

See http://www.boost.org/doc/libs/1_39_0/doc/html/unordered/buckets.html#unordered.buckets.controlling_the_number_of_buckets
--DD
Chris Miceli | 1 Jul 05:10
Favicon

[asio] ICMP protocol support


I am attempting to use the ICMP protocol that is "off-the-shelf" in
Boost.Asio, but am unable to get any use of it working.  Following the
code listed here:
http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/overview/networking/protocols.html
I immediately run into problems.  The DAYTIME protocol is defined to
operate on TCP or UDP port 13. ICMP should be used for control
messages, not data transmission.  Trying to connect to a server
supported DAYTIME with ICMP does not work using the code at the
previously mentioned site, this error is returned:
Service not found
Which makes sense because this service is not defined for this
protocol.  My question is, what is the intended purpose of the current
implementation of this protocol?  If to use ICMP to tranfer data by
using the payload, why?  If to construct messages useful for writing a
traceroute or ping utility, how would I do this?  Has anyone used this
library? Online there is a desire to use boost.Asio and ICMP to write
ping using boost, but they all reach these same questions.  I am
appreciative of any help on this topic.
-Chris
Laurent Fert | 1 Jul 05:58
Picon

[asio] Thread safety

Hi,

I have a thread that runs io_service::run().
I have another thread that creates a timer and schedules it to fire later.

Once the timer has been scheduled, the second thread forgets about it and everything is handled by the thread that runs the service.
Is it safe to create/schedule a timer with an io_service from a thread while this services is being run in another thread?

Thank you for your replies,

Laurent

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Vladimir Prus | 1 Jul 08:18

Re: STLPort Install Before Building Boost 1.39.0

biolaser wrote:

> I'm on Windows XP SP3, msvc71 SP1, and I want to install STLport 5.2.1
> before I install/build Boost 1.39.0. The STLport distribution install file
> (configure.bat) has two options I need help with:
> 
>  
> 
> "--with-static-rtl"
> 
>  
> 
> "-with-dynamic-rtl"
> 
>  
> 
> Does Boost care whether I enable the static (libc.lib family) or whether I
> enable the dynamic (msvcrt.lib family) C/C++ library when linking with
> STLport?

Not really, but it is better to use same setting for both. Boost uses dynamic
runtime by default, which seems like reasonable choice anyway.

> Then, there is the "-use-boost <boost install path>" option - I assume I
> should use this STLport option for Boost 1.39.0 - correct?

I'd expect that STLport docs say what this option does and whether it is needed.

> Finally, is there anything I need to do in my building/installing of Boost
> itself to make sure it knows I have STLport installed?

Yes, you should read docs:

        http://tinyurl.com/mvs5ge

- Volodya

Gmane