|
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óÃâÀ¢Çv2棦çEóÃâÀ¢³ÕÒWFòò²&WGW&ââ¢f7B
òâÒ棦çEóÃâ²Ð¢°¢Ð ¤Æ÷Böb7Vv"6÷VÆB&RFFVBFòWfÅöfÂƶR&WGFW"7çF¢6ÖÆ"FòöVæw2â÷FW"ö'f÷W2WFVç6öç2v÷VÆB&RF@¦çVÆÆ'ÆÖ&F26÷VÆB&R7W÷'FVBFöòâæöæRöbF2v2æ÷BFöæP§WB&V6W6RÆ6²FÖRæBvçFVBFò6öæ6VçG&FRöâFR&W76Væ6R"À¦æ÷BFR7Vv"à ¤Ç6òÂFW&R&R6WfW&Â6fVG2âf'7BÂ&V6W6RvRw&RW6ærÆÖ&F2À¦BÖVç2FBFRgVæ7Föâw2&W7VÇB6âwB&RW6VBâ6öç7FçBX]\È]ÛÛ\[\ÈÝ\[H]HÙ]\[YÜÂYØ\[ÈY\H\ÝY[X\ÈÚ]Ø\\\ËÛÈ[ÝH[Ø^\È\ÚÂÜ\Ú[ÈHÛÛ\[\]\È\ÈH]Y\Ý[ÛÙ[YHYÜH]\ÈÝHØ[H[[[ÜK[[K]YX[È]ÛÛ][Û[ÈØ[ÝHÜ][\XÝH[ÚYB[][X]YÛÛ^ËHX\ÛÛ\È]H[XHØ[Ý\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ÛÛ\]][ÛÈ[È\XXH[\]\È[Ý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