Topic: [std-proposals] Re: Adding the Keyword interface


Author: Mingxin Wang <wmx16835vv@163.com>
Date: Sun, 7 May 2017 22:29:42 -0700 (PDT)
Raw View
------=_Part_4_1656717978.1494221383074
Content-Type: multipart/alternative;
 boundary="----=_Part_5_858810948.1494221383075"

------=_Part_5_858810948.1494221383075
Content-Type: text/plain; charset=UTF-8

The implementation for the *Callable *interface was incorrect, and should
be as follows:

template <class R, class... Args>
class Callable {
 public:
  template <class Data>
  Callable(Data data) requires
      requires(Data data, Args... args) { { data(std::move(args)...) } ->
R; }
      : data_(new Implementation<Data>(std::move(data))) {}
  Callable() = default;
  Callable(Callable&&) = default;
  Callable(const Callable&) = default;
  Callable& operator=(Callable&&) = default;
  Callable& operator=(const Callable&) = default;

  *R operator()(Args... args) { return data_->op_0(std::move(args)...); }*

 private:
  class Abstraction {
   public:
    *virtual R op_0(Args&&...) = 0;*
    virtual ~Abstraction() {}
  };

  template <class Data>
  class Implementation final : public Abstraction {
   public:
    Implementation(Data&& data) : data_(std::forward<Data>(data)) {}
    *R op_0(Args&&... args) override { return
data_(std::forward<Args>(args)...); }*

   private:
    Data data_;
  };

  std::shared_ptr<Abstraction> data_;
};


--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/e700af7e-aee3-4ba9-b899-2f603fed1e72%40isocpp.org.

------=_Part_5_858810948.1494221383075
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><font face=3D"georgia, serif">The implementation for the <=
b>Callable </b>interface was incorrect, and should be as follows:</font><di=
v><font face=3D"georgia, serif"><br></font></div><div><div class=3D"prettyp=
rint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word;=
 background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div cl=
ass=3D"subprettyprint"><font color=3D"#660066"><div class=3D"subprettyprint=
">template &lt;class R, class... Args&gt;</div><div class=3D"subprettyprint=
">class Callable {</div><div class=3D"subprettyprint">=C2=A0public:</div><d=
iv class=3D"subprettyprint">=C2=A0 template &lt;class Data&gt;</div><div cl=
ass=3D"subprettyprint">=C2=A0 Callable(Data data) requires</div><div class=
=3D"subprettyprint">=C2=A0 =C2=A0 =C2=A0 requires(Data data, Args... args) =
{ { data(std::move(args)...) } -&gt; R; }</div><div class=3D"subprettyprint=
">=C2=A0 =C2=A0 =C2=A0 : data_(new Implementation&lt;Data&gt;(std::move(dat=
a))) {}</div><div class=3D"subprettyprint">=C2=A0 Callable() =3D default;</=
div><div class=3D"subprettyprint">=C2=A0 Callable(Callable&amp;&amp;) =3D d=
efault;</div><div class=3D"subprettyprint">=C2=A0 Callable(const Callable&a=
mp;) =3D default;</div><div class=3D"subprettyprint">=C2=A0 Callable&amp; o=
perator=3D(Callable&amp;&amp;) =3D default;</div><div class=3D"subprettypri=
nt">=C2=A0 Callable&amp; operator=3D(const Callable&amp;) =3D default;</div=
><div class=3D"subprettyprint"><br></div><div class=3D"subprettyprint">=C2=
=A0 <b>R operator()(Args... args) { return data_-&gt;op_0(std::move(args)..=
..); }</b></div><div class=3D"subprettyprint"><br></div><div class=3D"subpre=
ttyprint">=C2=A0private:</div><div class=3D"subprettyprint">=C2=A0 class Ab=
straction {</div><div class=3D"subprettyprint">=C2=A0 =C2=A0public:</div><d=
iv class=3D"subprettyprint">=C2=A0 =C2=A0 <b>virtual R op_0(Args&amp;&amp;.=
...) =3D 0;</b></div><div class=3D"subprettyprint">=C2=A0 =C2=A0 virtual ~Ab=
straction() {}</div><div class=3D"subprettyprint">=C2=A0 };</div><div class=
=3D"subprettyprint"><br></div><div class=3D"subprettyprint">=C2=A0 template=
 &lt;class Data&gt;</div><div class=3D"subprettyprint">=C2=A0 class Impleme=
ntation final : public Abstraction {</div><div class=3D"subprettyprint">=C2=
=A0 =C2=A0public:</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 Implemen=
tation(Data&amp;&amp; data) : data_(std::forward&lt;Data&gt;(data)) {}</div=
><div class=3D"subprettyprint">=C2=A0 =C2=A0 <b>R op_0(Args&amp;&amp;... ar=
gs) override { return data_(std::forward&lt;Args&gt;(args)...); }</b></div>=
<div class=3D"subprettyprint"><br></div><div class=3D"subprettyprint">=C2=
=A0 =C2=A0private:</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 Data da=
ta_;</div><div class=3D"subprettyprint">=C2=A0 };</div><div class=3D"subpre=
ttyprint"><br></div><div class=3D"subprettyprint">=C2=A0 std::shared_ptr&lt=
;Abstraction&gt; data_;</div><div class=3D"subprettyprint">};</div></font><=
/div></code></div><br><br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/e700af7e-aee3-4ba9-b899-2f603fed1e72%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e700af7e-aee3-4ba9-b899-2f603fed1e72=
%40isocpp.org</a>.<br />

------=_Part_5_858810948.1494221383075--

------=_Part_4_1656717978.1494221383074--

.