// // Copyright (c) 2012-2020 Kris Jusiak (kris at jusiak dot net) // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include #include #include #include #include #include "example/polymorphism/common/config.hpp" /*<>*/ class Drawable : public std::function { public: using std::function::function; }; class App { public: explicit App(const Drawable drawable) : drawable{drawable} {} void draw(std::ostream& out) const { drawable(out); } private: const Drawable drawable; }; struct Square { void operator()(std::ostream& out) const { out << "Square"; } }; struct Circle { void operator()(std::ostream& out) const { out << "Circle"; } }; int main() { std::stringstream str{}; auto example = config().create(); example.draw(str); assert("Square" == str.str()); }