Boost logo

Boost :

Subject: Re: [boost] Pimpl Again?
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-05-31 20:01:30


On 1/06/2016 11:48, Emil Dotchevski wrote:
> No, I said non-friend. Look, there is no semantic difference between
> allowing non-friend member functions to be added without changes to the
> type definition on one hand, and allowing non-friend free functions to be
> added without changes to the type definition on the other hand. Neither
> breaks the encapsulation; the difference is entirely syntactic.

This is basically what .NET extension methods do -- they're static
functions outside of a class declared with some initial parameter of a
particular type. They can be invoked either as static methods passing
the parameters exactly as declared, or as if they were member functions
where the initial parameter is removed from the argument list and placed
before the dot instead.

eg. public static int Sum(this IEnumerable<int> list), which can be
called just as list.Sum() on any IEnumerable<int>.

It's purely syntactic but allows for some highly readable code.
(Although it's easy to get carried away sometimes.)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk