Giter Club home page Giter Club logo

polymorphic_value's Introduction

A polymorphic value-type for C++

The class template polymorphic_value is proposed for addition to the C++ Standard Library.

The class template, polymorphic_value, confers value-like semantics on a free-store allocated object. A polymorphic_value<T> may hold a an object of a class publicly derived from T, and copying the polymorphic_value will copy the object of the derived type.

Using polymorphic_value a copyable composite object with polymorphic components can be written as:

// Copyable composite with mutable polymorphic components
class CompositeObject {
  std::polymorphic_value<IComponent1> c1_;
  std::polymorphic_value<IComponent2> c2_;

 public:
  CompositeObject(std::polymorphic_value<IComponent1> c1,
                  std::polymorphic_value<IComponent2> c2) :
                    c1_(std::move(c1)), c2_(std::move(c2)) {}

  // `polymorphic_value` propagates constness so const methods call 
  // corresponding const methods of components
  void foo() const { c1_->foo(); }
  void bar() const { c2_->bar(); }

  void foo() { c1_->foo(); }
  void bar() { c2_->bar(); }
};

Submodules

Tests use the 'catch' test framework: https://github.com/philsquared/Catch.git

To get the submodule run:

git submodule update --init

Building

The build uses cmake driven by a simple Python script. To build and run tests, run the following from the console:

./scripts/build.py --tests

Build status

  • on Travis: Travis Build Status
  • on AppVeyor: AppVeyor Build Status

ISO Standardisation

polymorphic_value has been proposed for standardisation for C++20 in P0201: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0201r1.pdf. The draft in this repository is more up to date than the paper linked above, in particular the class has been renamed from indirect to polymorphic_value.

polymorphic_value's People

Contributors

jbcoe avatar ajbennieston avatar

Watchers

James Cloos avatar Richard Maierhofer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.