Skip to content

ericniebler/any

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI

any

A C++23 library for building type-erasing wrappers.

#include "any/any.hpp"

#include <cassert>
#include <cstdio>

// "abstract" interfaces:
template <class Model>
struct idrawable : any::interface<idrawable, Model>
{
  using idrawable::interface::interface;

  constexpr virtual void draw() const
  {
    any::value(*this).draw();
  }
};

namespace my
{
// A concrete type that models the interface but
// that does not inherit from it:
struct drawable
{
  void draw() const
  {
    std::printf("my::drawable::draw()\n");
  }
};
} // namespace my

int main()
{
  any::any<idrawable> widget = my::drawable{};

  // prints "my::drawable::draw()":
  widget.draw();
}

About

a library for building type-erasing wrappers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors