Toward Opaque Typedefs for C++1Y

284 views
Skip to first unread message

Vicente J. Botet Escriba

unread,
Feb 3, 2013, 11:24:49 AM2/3/13
to std-pr...@isocpp.org
Hi,

N3515 uses the following syntax to change the return type and to delete some non-member operator

using energy = protected double {
  energy  operator+ (energy , energy) = default;
  energy& operator*=(energy&, double) = default;
  energy  operator* (energy , energy) = delete;
  energy  operator* (energy , double) = default;
  energy  operator* (double , energy) = default;
};

How the compiler would make the difference between member and non-member functions?

BTW, 

  energy& operator*=(energy&, double) = default;

should be

  energy& operator*=(double) = default;

As operator*= can be overloaded only inside a class.


I see thatsome parts have been removed from the previous version, as

". How shall OT’s unary type traits be defined?
Proposed answer: for each category and property defined by TR1, is_category(OT) ==
is_category(UT) shall be true, and
has_property(OT) == has_property(UT) shall also be true"

substitutability and casts. There were some opposition to these parts from the comitte? Could you explain why you removed them?

Best,
Vicente

Vicente J. Botet Escriba

unread,
Feb 3, 2013, 12:01:48 PM2/3/13
to std-pr...@isocpp.org
Le 03/02/13 17:24, Vicente J. Botet Escriba a �crit :

Hi again, one more question. Could we forward declare an opaque type,
so that two opaque types can refer to each other?

using X=?.

using Y = protected double {
Y operator* (Y , X);
};

using X = protected double {
X operator* (X , Y);
};

Best,
Vicente

mitc...@gmail.com

unread,
Mar 18, 2014, 5:44:47 AM3/18/14
to std-pr...@isocpp.org
Shouldn't the example in section 9 (Opaque template aliases) in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3515.pdf use T instead of double? Like this:

template <class T = double> using energy = protected T {
   energy operator+ (energy , energy) = default;
   energy& operator*=(energy&, T) = default;
   energy operator* (energy , energy) = delete;
   energy operator* (energy , T) = default;
   energy operator* (T , energy) = default;
};

Matheus Izvekov

unread,
Mar 18, 2014, 6:52:41 AM3/18/14
to std-pr...@isocpp.org
On Sunday, February 3, 2013 2:24:49 PM UTC-2, Vicente J. Botet Escriba wrote:
Hi,

N3515 uses the following syntax to change the return type and to delete some non-member operator

using energy = protected double {
  energy  operator+ (energy , energy) = default;
  energy& operator*=(energy&, double) = default;
  energy  operator* (energy , energy) = delete;
  energy  operator* (energy , double) = default;
  energy  operator* (double , energy) = default;
};

How the compiler would make the difference between member and non-member functions?


I don't think the member forms of the operators are supposed to be supported.
 
BTW, 

  energy& operator*=(energy&, double) = default;

should be

  energy& operator*=(double) = default;

As operator*= can be overloaded only inside a class.


I think that's on purpose, it is meant to introduce a new non-member operatorX= form.

Scott Prager

unread,
Apr 3, 2014, 1:31:27 AM4/3/14
to std-pr...@isocpp.org


On Sunday, February 3, 2013 12:01:48 PM UTC-5, Vicente J. Botet Escriba wrote:
Le 03/02/13 17:24, Vicente J. Botet Escriba a �crit :

Hi again,  one more question. Could we forward declare an opaque type,
so that two opaque types can refer to each other?

The paper says:

Much like a classical typedef, such a declaration introduces a new name (the identifier) for an
opaque type that implicitly shares the definition of the underlying type named by the type-id.
Thus, every opaque alias constitutes a definition; there are no forward declarations of an opaque
type.
 

using X=?.

using Y = protected double {
   Y  operator* (Y , X);
};

using X = protected double {
   X  operator* (X , Y);
};

I can think of an example where this would be useful (representing angles with Radians and Degrees where there exists no common type to "trampoline" off of). It's interesting because we can't necessarily forward declare typedefs and aliases in any useful way, but we can for types and these opaque template aliases aim to look like types. 
 

Best,
Vicente
Reply all
Reply to author
Forward
0 new messages