|
Boost : |
Subject: Re: [boost] [Fit] Review
From: paul Fultz (pfultz2_at_[hidden])
Date: 2016-03-11 14:41:22
> On Friday, March 11, 2016 12:30 PM, Bjorn Reese <breese_at_[hidden]> wrote:
> > On 03/11/2016 01:50 AM, Paul Fultz II wrote:
>
>> library. I do, however, need to discuss some of the misperceived issues
> with
>> using global function objects in the documentation. As the issues raised in
>> the review were:
>
> The destruction order of global objects in different translation units
> is undefined. This means that I cannot use a global fit function in the
> destructor of one of my own global objects because the former may have
> been destroyed before the latter.
This is not a problem, because it is initialized at compile-time, that means
it is a literal type:
http://en.cppreference.com/w/cpp/concept/LiteralType
So besides the constructor not having side-effects, the destructor must be
trivial, as well. For example, this cannot compile:
struct foo_fn
{
template<class... Ts>
auto operator()(Ts&&...) const
{}
~foo_fn()
{
std::cout << "Hello";
}
};
BOOST_FIT_STATIC_FUNCTION(foo) = foo_fn();
int main() {
foo();
}
So with trivial destructors, the order of destruction doesn't matter.
Furthermore, on most compilers(that is everything but MSVC), the function is
the same across all translation units. So there is only one function in the
executable, not one per translation unit. Taking the address of the function
will yield the same address across all translation units. This is the same way
functions work.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk