220 6857 <27c90f45-8ae6-44c1-8755-2b4cece26bcb@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Proposal: Class Frames to inject prefabricated
 features into classes
Date: Tue, 1 Oct 2013 11:33:12 -0700 (PDT)
Lines: 197
Approved: news@gmane.org
Message-ID: <27c90f45-8ae6-44c1-8755-2b4cece26bcb@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_28_29558813.1380652392376"
X-Trace: ger.gmane.org 1380652394 30832 80.91.229.3 (1 Oct 2013 18:33:14 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 1 Oct 2013 18:33:14 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDC55PNFRYGRB2VKVSJAKGQEEX4SENA@isocpp.org Tue Oct 01 20:33:16 2013
Return-path: <std-proposals+bncBDC55PNFRYGRB2VKVSJAKGQEEX4SENA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f71.google.com ([209.85.219.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDC55PNFRYGRB2VKVSJAKGQEEX4SENA@isocpp.org>)
	id 1VR4l1-0007l0-M3
	for gclcip-std-proposals@m.gmane.org; Tue, 01 Oct 2013 20:33:15 +0200
Original-Received: by mail-oa0-f71.google.com with SMTP id f4sf23621501oah.10
        for <gclcip-std-proposals@m.gmane.org>; Tue, 01 Oct 2013 11:33:14 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe:content-type;
        bh=0ACpLPhd6jbswJvn3o+ZMYthNqdS7MAatubvIKX77/Q=;
        b=pG0ClD79bEwCJ3O8fX9PeFwVNvweNh3o71qTDSsIS1hPuoXTK4ebtRyTalIKWc6PNM
         MH7Teu56JVC9jwWgmmOguV91hYrYQH78RQ3PFQAM5TfJsDRAyyU98W+4YChRvVpJv5Cc
         ky2gLIqPDXYA0SlTMcWuZTmRnQ/38xk/P2HWk8KefuVlU+whQBTkTQeYLSWZaazgsfIz
         pJJxeUQB7TFFffGlOGz8A1CwrIX6OJjKfSa5ctiLvUOPd6PjkkmuHCEvaxUQbry6loOS
         PpuFeAzEwc1NgkBpCRC52VgQNkuUlz2MpiuRCK0Zs47jR3jHT/tOZH5hC5HX7Vthx6FY
         NBTA==
X-Received: by 10.42.83.200 with SMTP id i8mr4894737icl.17.1380652394648;
        Tue, 01 Oct 2013 11:33:14 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.40.36 with SMTP id u4ls334118igk.2.gmail; Tue, 01 Oct 2013
 11:33:13 -0700 (PDT)
X-Received: by 10.50.136.133 with SMTP id qa5mr731588igb.4.1380652393790;
        Tue, 01 Oct 2013 11:33:13 -0700 (PDT)
X-Original-Sender: mikhailsemenov1957@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:6857
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/6857>

------=_Part_28_29558813.1380652392376
Content-Type: text/plain; charset=ISO-8859-1

I propose to introduce class frames, which allow to inject features into 
classes, which in most cases are not available through inheritance. In 
addition, they
don't require virtual functions, which makes them more efficient.
 
*Part I*
The frame provides features that are required for a class to be 
constructed; it and starts with a header:
*class FrameName(class T)
*or
*struct FrameName(class T)*


For example:

*class MoveInjection(class T)
{
public:
  T();        // to be defined in the class
  T(const T&);// to be defined in the class
  virtual ~T();// to be defined in the class
  void swap(T&);// to be defined in the class
  *

*  T(T&& b):T() // is provided for the class
  {
     swap(b);
  }*

*  T& operator=(const T& b) // is provided for the class
  {
     T c(b);
     swap(c);
     return *this;
  }*

*  T& operator=(T&& b) // is provided for the class
  {
     swap(b);
     return *this;
  }
};*


The MoveInjection frame allows to create a class with a move constructor 
and assignment much easier: the programmer
has to provide the definitions for T(), T(const& T&), ~T() and swap:

*class A using MoveInjection
{
public:
   A() {...}
   A(const A& a) { ... }
   virtual ~A() { ... }
   void swap(T& a) { ... }
};*

 

The class frame may contain static objects:

*class AddInjection(class T)
{
   static friend T operator+(class T& a, class T& b);
};*


*Part II*

If the parameter inside a frame is not used, it can be dropped. In this 
case,
it is possible to write:

*class IntegralInjection()
{
public:
    double integral(std::function<double(double)>, double a, double b);
};*

Such class frames can be used in a similar way:
*class B using IntegralInjection
{
public:
    double integral(std::function<double(double)>, double a, double b)
    {
      ...
    }
    ...
};*

But it is also possible to use such class frames in templates:

*template Integrate<class A using IntegralInjection>
....*
which means that this template requires the class to contain an integral 
function, which the given header.
 
*Additional features of class frames*
 
(1) It should be possible to use several frames to inject various features 
into a class. 
 
(2) A class frame itself can be defined in a template:
*template<class A>*
*class SpecialInjection(class B)*
*{*
*....*
*};*

** 

 

 

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_28_29558813.1380652392376
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I propose to introduce class frames, which allow to i=
nject features into classes, which in most cases are not available through =
inheritance. In addition, they</div><div>don't require virtual functions, w=
hich makes them more efficient.</div><div>&nbsp;</div><div><strong><u>Part =
I</u></strong><font face=3D"trebuchet ms,sans-serif" style=3D"background-co=
lor: rgb(153, 0, 255);"><br></font></div><div>The frame provides features t=
hat are required for a class to be constructed; it and starts with a header=
:<br><strong>class FrameName(class T)<br></strong>or<br><strong>struct Fram=
eName(class T)</strong></div><p><br>For example:</p><p><strong>class MoveIn=
jection(class T)<br>{<br>public:<br>&nbsp; T();&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp; // to be defined in the class<br>&nbsp; T(const T&amp;);// t=
o be defined in the class<br>&nbsp; virtual ~T();// to be defined in the cl=
ass<br>&nbsp; void swap(T&amp;);// to be defined in the class<br>&nbsp; </s=
trong></p><p><strong>&nbsp; T(T&amp;&amp; b):T() // is provided for the cla=
ss<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; swap(b);<br>&nbsp; }</strong></p=
><p><strong>&nbsp; T&amp; operator=3D(const T&amp; b) // is provided for th=
e class<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; T c(b);<br>&nbsp;&nbsp;&nbs=
p;&nbsp; swap(c);<br>&nbsp;&nbsp;&nbsp;&nbsp; return *this;<br>&nbsp; }</st=
rong></p><p><strong>&nbsp; T&amp; operator=3D(T&amp;&amp; b) // is provided=
 for the class<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; swap(b);<br>&nbsp;&n=
bsp;&nbsp;&nbsp; return *this;<br>&nbsp; }<br>};</strong></p><p><br>The Mov=
eInjection frame allows to create a class with a move constructor and assig=
nment much easier: the programmer<br>has to provide the definitions for T()=
, T(const&amp; T&amp;), ~T() and swap:</p><p><strong>class A using MoveInje=
ction<br>{<br>public:<br>&nbsp;&nbsp; A() {...}<br>&nbsp;&nbsp; A(const A&a=
mp; a) { ... }<br>&nbsp;&nbsp; virtual ~A() { ... }<br>&nbsp;&nbsp; void sw=
ap(T&amp; a) { ... }<br>};</strong></p><p>&nbsp;</p><p>The class frame may =
contain static objects:</p><p><strong>class AddInjection(class T)<br>{<br>&=
nbsp;&nbsp; static friend T operator+(class T&amp; a, class T&amp; b);<br>}=
;</strong></p><p><br><strong><u>Part II</u></strong></p><p>If the parameter=
 inside a frame is not used, it can be dropped. In this case,<br>it is poss=
ible to write:</p><p><strong>class IntegralInjection()<br>{<br>public:<br>&=
nbsp;&nbsp;&nbsp; double integral(std::function&lt;double(double)&gt;, doub=
le a, double b);<br>};</strong></p><p>Such class frames can be used in a si=
milar way:<br><strong>class B using IntegralInjection<br>{<br>public:<br>&n=
bsp;&nbsp;&nbsp; double integral(std::function&lt;double(double)&gt;, doubl=
e a, double b)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ..=
..<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; ...<br>};</strong></p><p>Bu=
t it is also possible to use such class frames in templates:</p><p><strong>=
template Integrate&lt;class A using IntegralInjection&gt;<br>...</strong></=
p><div>which means that this template requires the class to contain an inte=
gral function, which the given header.</div><div>&nbsp;</div><div><strong><=
u>Additional features of class frames</u></strong></div><div>&nbsp;</div><d=
iv>(1) It&nbsp;should be&nbsp;possible to use several frames to inject vari=
ous features into a class. </div><div>&nbsp;</div><div>(2) A class frame it=
self can be defined in a template:</div><div><strong>template&lt;class A&gt=
;</strong></div><div><strong>class SpecialInjection(class B)</strong></div>=
<div><strong>{</strong></div><div><strong>....</strong></div><div><strong>}=
;</strong></div><p><strong></strong>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p></d=
iv>

<p></p>

-- <br />
&nbsp;<br />
--- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_28_29558813.1380652392376--

.
