-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


C++

, 27 2017 . 17:38 +
++ . 2 , , .

, ? ++ , , , : , , . - ( enum classes) - . - . , (, , ) ( ). properties , value- (- , // , ). - - . Qt , moc. C++/CLI C++/CX . ..

, . , .

. , , / .

, . ? , # 18 . :

  1. , 18
  2. ++ ( ++ ). . 1, 2 3.

, , - , . ! , - 18 , 99.99% . .

, :

$class interface {
  constexpr 
  {
    compiler.require($interface.variables().empty(),
      " -  !");
  
    for (auto f : $interface.functions()) 
    {
      compiler.require(!f.is_copy() && !f.is_move(),
        "    ; "
        "virtual clone()  ");

      if (!f.has_access()) 
        f.make_public(); //    !

      compiler.require(f.is_public(), // ,  
        "interface functions must be public");

    f.make_pure_virtual();  //    
    }
  }

  //     ++    , 
  //      
  virtual ~interface() noexcept { } 
};

interface, ( constexpr) , , .

:

interface Shape 
{
  int area() const;
  void scale_by(double factor);
};

, C# Java? Shape interface, :

class Shape 
{
public:
  virtual int area() const =0;
  virtual void scale_by(double factor) =0;
  virtual ~Shape() noexcept { };
};

-.
, Shape -. , , , ..

, .
, . , ordered- - :

class Point 
{
  int x = 0;
  int y = 0;
public:
  Point() = default;
  friend bool operator==(const Point& a, const Point& b)
   { return a.x == b.x && a.y == b.y; }
  friend bool operator< (const Point& a, const Point& b)
   { return a.x < b.x || (a.x == b.x && a.y < b.y); }
  friend bool operator!=(const Point& a, const Point& b) { return !(a == b); }
  friend bool operator> (const Point& a, const Point& b) { return b < a; }
  friend bool operator>=(const Point& a, const Point& b) { return !(a < b); }
  friend bool operator<=(const Point& a, const Point& b) { return !(b < a); }
};

, - :

$class ordered {
  constexpr {
    if (! requires(ordered a) { a == a; }) -> 
    {
      friend bool operator == (const ordered& a, const ordered& b) 
      {
        constexpr 
        {
          for (auto o : ordered.variables()) // for each member
            -> { if (!(a.o.name$ == b.(o.name)$)) return false; }
        }
        return true;
      }
    }
    if (! requires(ordered a) { a < a; }) -> 
    {
      friend bool operator < (const ordered& a, const ordered& b) 
      {
        for (auto o : ordered.variables()) -> 
        {
          if (a.o.name$ < b.(o.name)$) return true; 
          if (b.(o.name$) < a.o.name$) return false; )
        }
        return false;
      }
    }
    if (! requires(ordered a) { a != a; })
      -> { friend bool operator != (const ordered& a, const ordered& b) { return !(a == b); } }
    if (! requires(ordered a) { a > a; })
      -> { friend bool operator > (const ordered& a, const ordered& b) { return b < a ; } }
    if (! requires(ordered a) { a <= a; })
      -> { friend bool operator <= (const ordered& a, const ordered& b) { return !(b < a); } }
    if (! requires(ordered a) { a >= a; })
      -> { friend bool operator >= (const ordered& a, const ordered& b) { return !(a < b); } }
  }
};

? ? , - Boost. , :

ordered Point 
{ 
  int x; 
  int y; 
};

!

, , , pair tuple :

template
literal_value pair 
{
  T1 first;
  T2 second;
};

, , .

:

  • " "
  • , value-, properties
  • Moc Qt ++/CLI C++/CX,
  • ,
  • , , , ?

- ! ?

, :




-, .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/334284/

:  

: [1] []
 

:
: 

: ( )

:

  URL