Boost logo

Boost :

Subject: Re: [boost] [mpl] multiset
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2015-03-10 19:31:16


Zach Laine <whatwasthataddress <at> gmail.com> writes:

>
> On Sun, Mar 8, 2015 at 2:56 PM, Eric Niebler <eniebler <at> boost.org> wrote:
>
> [...]
>
> > As for lazy branches, that can also be handled simply by let/defer:
> >
> > // Test that the unselected branch does not get evaluated:
> > template<typename T>
> > using test_lazy_if_ =
> > let<lazy::if_<std::is_void<T>, T, defer<std::pair, T> > >;
> > static_assert(std::is_same<test_lazy_if_≤void>, void>::value, "");
> >
>
> And don't forget this part! :)

Oops, I forgot. Ok, so lazy branches in Hana work as follows. First, you
use the `eval_if` function, which takes a condition and two branches in
the form of lambdas. But that's not all; the lambdas must accept a parameter
(usually called _), ¥ …¸‰”ÕÍ•Ñ¼‘•™•ÈÑ¡”½µÁ¥±”µÑ¥µ”•Ù…±Õ…Ñ¥½¸)½˜•áÁÉ•ÍÍ¥½¹Ì…́ɕÅեɕ¸¸•á…µÁ±”è((€€€Ñ•µÁ±…Ñ”€ñÑåÁ•¹…µ”8ø(€€€…ÕѼ™…Ð¡8¸¤ì(€€€€€€€É•ÑÕɸ¡…¹„èé•Ù…±}¥˜¡¸€ôô¡…¹„è饹Ñ|ðÀø°(€€€€€€€€€€€mt¡…ÕѼ|¤ìÉ•ÑÕɸ¡…¹„è饹Ñ|ðÄøìô°(€€€€€€€€€€€lõt¡…ÕѼ|¤ìÉ•ÑÕɸ¸€¨™…Ð¡|¡¸¤€´¡…¹„è饹Ñ|ðÄø¤ìô(€€€€€€€€¤ì(€€€ô()]¡…Ё¡…ÁÁ•¹Ì¡•É”¥ÌÑ¡…Ё•Ù…±}¥™€Ý¥±°Á…Í́…¸¥‘•¹Ñ¥Ñ䁙չÑ¥½¸Ñ¼)Ñ¡”Í•±•Ñ•‰É…¹ ¸!•¹”°|¡à¥€¥Ì…±Ý…ǻѡ”Í…µ”…́á€°‰ÕЁѡ”)½µÁ¥±•È…¸ÐÑ•±°Õ¹Ñ¥°Ñ¡”±…µ‰‘„¡…́‰••¸…±±•„!•¹”°Ñ¡”½µÁ¥±•È)¡…́ѼÝ…¥Ð‰•™½É”¥Ð¥¹ÍÑ…¹Ñ¥…ѕ́ѡ”‰½‘䁽˜Ñ¡”±…µ‰‘„…¹¹¼¥¹™¥¹¥Ñ”€)É•ÕÉÍ¥½¸¡…ÁÁ•¹Ì¸±Í¼¹½Ñ”Ñ¡…Ё…±Ý…åÍ€…¸‰”ÕÍ•Ñ¼µ…­”•Ù…±}¥™€€)•…Í¥•ÈÑ¼Ý½É¬Ý¥Ñ è((€€€Ñ•µÁ±…Ñ”€ñÑåÁ•¹…µ”8ø(€€€…ÕѼ™…Ð¡8¸¤ì(€€€€€€€GW&â†æ£¦WfÅö–b†âÓ҆棦–çEóÃâÀ¢Çv—2††æ£¦–çEóÃâ’À¢³ÕÒ†WFòò’²&WGW&ââ¢f7B…ò†â’҆棦–çEóÃ⓲Т“°¢Р¤Æ÷Böb7Vv"6÷VÆB&RFFVBFòWfÅö–fÂÆ–¶R&WGFW"7–çF€¢‡6–Ö–Æ"Fò†öVæ—‚w2’â÷F†W"ö'f–÷W2W‡FVç6–öç2v÷VÆB&RF†@¦çVÆÆ'’ÆÖ&F26÷VÆB&R7W÷'FVBFöòâæöæRöbF†—2v2æ÷BFöæP§–WB&V6W6R’Æ6²F–ÖRæBvçFVBFò6öæ6VçG&FRöâF†R&W76Væ6R"À¦æ÷BF†R7Vv"à ¤Ç6òÂF†W&R&R6WfW&Â6fVG2âf—'7BÂ&V6W6RvRw&RW6–ærÆÖ&F2À¦—BÖVç2F†BF†RgVæ7F–öâw2&W7VÇB6âwB&RW6VB–â6öç7FçB™X]\È]ÛÛ\[\œÈÝ\œ™[H]™HÙ]™\˜[YÜÂœ™YØ\™[™ÈY\H™\ÝY[X™\ÈÚ]Ø\\™\ˈÛÈ[ÝH[Ø^\Èš\Ú˜ܘ\Ú[™ÈHÛÛ\[\‹]\È\ÈH]Y\Ý[ÛˆÙˆ[YH™Y›Ü™H]\È››ÝH›Ø›[H[ž[[Ü™K‚‚‘š[˜[K]YX[œÈ]ÛÛ™][Û˜[ÈØ[‰Ý™HÜš][ˆ\™XÝH[œÚYB[™]˜[X]YÛ۝^ˈH™X\ÛÛˆ\È]H[X™HØ[‰Ý\X\ˆ[ˆ[‚[™]˜[X]YÛ۝^ ›Üˆ^[\H[ˆXÛ\X ˆ\™H\™HÛÛÙ™X\Ûۜ™›Üˆ\È™\ÝšXÝ[Ûˆ[ˆH[™ÝXYÙK]HÝ\œ™[ÛÜ™[™È\ÈØ^BÛÈÝšXÝSSˈHÛÝ[™HÚ[[™ÈÈX[H\›ÜˆH\\ˆ™YØ\™[™È\ÈÛˈÛ™HØ^HÈÛÜšØ\›Ý[™\È\ÈÈÛÛ\][HY[Ý\ˆ\H˜ÛÛ\]][ÛœÈ[È˜\šXX›H[\]\È[œÝXY ˆÛÈ[œÝXYوܚ][™È™K™Ëˆ
Ý\Y^[\K\ÝÈÚÝÊB‚ˆ[\]H\[˜[YH‚ˆÝ f : decltype(eval_if(true_,
            [](auto _) { return type<T>; },
            [](auto _) { return type<T>; }
        ))
    { };

you could instead write

    template <typename T>
    auto f_impl(_type<T> t) {
        return eval_if(true_,
            [](auto) { return type<T>; },
            [](auto) { return type<T>; }
        );
    }

    template <typename T>
    using f = decltype(f_impl(type<T>));

Now, this hoop-jumping only has to be done in one place, because you
use (or should be using) normal function notation everywhere else in
your metaprogram to perform type computations. So the syntactic cost
is amortized. Also, it should be the case that

    template <typename T>
    auto f_impl = eval_if(true_,
        [](auto) { return type<Tô°(€€€€€€€mt¡…ÕѼ¤ìÉ•ÑÕɸÑåÁ”ñPøìô(€€€€¤ì()¥ÌÙ…±¥¸!•¹”°å½Ô½Õ±ÕÍ”Ù…É¥…‰±”Ñ•µÁ±…ѕ́Ѽ•…Í¥±ä‰É¥‘”€)‰•ÑÝ••¸!…¹„…¹…¹äÑåÁ”µ½¹±ä€¡Ý•…­•È„¤¥¹Ñ•É™…”¸!½Ý•Ù•È°Ñ¡”€)…‰½Ù”ÕÉÉ•¹Ñ±ä™…¥±ÌÑ¼½µÁ¥±”½¸ ±…¹œ€¡¥ÐÕÍ•Ñ¼Ý½É¬°$±°)¥¹Ù•ÍÑ¥…Ñ”…¹™¥±°„‰ÕœÉ•Á½ÉФ¸(()I•…É‘Ì°)1½Õ¥Ì


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