Groups | Search | Server Info | Login | Register
Groups > comp.lang.c++.moderated > #7420
| Message-ID | <5a3763cd-aecd-4f70-b858-94830f1fcf3f@googlegroups.com> (permalink) |
|---|---|
| Newsgroups | comp.lang.c++.moderated |
| From | pfultz2 <pfultz2@this.is.invalid> |
| Subject | Re: Global lambdas and ODR |
| Organization | unknown |
| References | <4719a003-d049-46db-b4b4-9bdae971863c@googlegroups.com> |
| Date | 2016-04-11 19:30 -0600 |
On Thursday, April 7, 2016 at 8:00:13 PM UTC-5, raskolnikov wrote:
> { edited by mod to shorten lines to ~70 characters. -mod }
>
> Hi!
>
> I was thinking about what some people including I are trying with
> transducers in C++14, which involves defining global lambdas [1] [2].
>
> However, I am becoming afraid that this in fact violates the One
> Definition Rule. Not only is the object defined in multiple
translation
> units, it is even defined with different types!
You may want to look at this, which discusses these issues:
http://pfultz2.com/blog/2015/05/31/unique-address/
The difficult problem with lambdas is that they are not constexpr.
Otherwise,
you could just write:
template<class T>
constexpr auto global = T{};
template<class T>
const auto& static_const_var(const T&)
{
return global<T>;
}
constexpr auto&& lambda = static_const_var([]{ ... });
In the Fit library[1], I would like to support the factory pattern for
lambdas, so you could write this:
auto lambda_factor()
{
return []{ ... };
}
FIT_STATIC_FUNCTION(lambda) = fit::indirect(&lambda_factor, fit::apply);
The fit::indirect adaptor needs to be extended to support a custom
operator.
I don't know if any of those patterns will help you with your
transducers.
Paul
[1]: https://github.com/pfultz2/Fit
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to comp.lang.c++.moderated | Previous | Next — Previous in thread | Next in thread | Find similar
Global lambdas and ODR raskolnikov <magnicida@googlemail.com> - 2016-04-07 19:56 -0600
Re: Global lambdas and ODR pfultz2 <pfultz2@this.is.invalid> - 2016-04-11 19:30 -0600
Re: Global lambdas and ODR Juan Pedro Bolivar Puente <raskolnikov@gnu.org> - 2016-04-12 06:49 -0600
Re: Global lambdas and ODR Juan Pedro Bolivar Puente <raskolnikov@gnu.org> - 2016-04-12 06:49 -0600
Re: Global lambdas and ODR pfultz2 <pfultz2@this.is.invalid> - 2016-04-12 12:53 -0600
csiph-web