Quantcast

[type_erasure] member function return any

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[type_erasure] member function return any

Boost - Users mailing list
Hello!

I want to return type_erasure::any from a member function of a struct
adapted by that same any. How can I do this?


#include <boost/type_erasure/any.hpp>
#include <boost/type_erasure/callable.hpp>

using my_any = boost::type_erasure::any<
    boost::mpl::vector<
        boost::type_erasure::copy_constructible<>,
        boost::type_erasure::assignable<>,
        boost::type_erasure::callable<? ? ?>
    >
>;

struct s
{
    my_any operator()(my_any v)
    {
        return v;
    }
};

int main()
{
    my_any t = s{};
    t = t(t);
}

Thanks.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [type_erasure] member function return any

Boost - Users mailing list
AMDG

On 03/06/2017 04:59 AM, Mikhail Strelnikov via Boost-users wrote:
>
> I want to return type_erasure::any from a member function of a struct
> adapted by that same any. How can I do this?
>

For this to work you need to forward declare
the Concept:

struct my_concept;
using my_any = boost::type_erasure::any<my_concept>;
struct my_concept : boost::mpl::vector<
  copy_constructible<>,
  assignable<>,
  callable<my_any(my_any)>> {};

>
> #include <boost/type_erasure/any.hpp>
> #include <boost/type_erasure/callable.hpp>
>
> using my_any = boost::type_erasure::any<
>     boost::mpl::vector<
>         boost::type_erasure::copy_constructible<>,
>         boost::type_erasure::assignable<>,
>         boost::type_erasure::callable<? ? ?>
>     >
>> ;
>
> struct s
> {
>     my_any operator()(my_any v)
>     {
>         return v;
>     }
> };
>
> int main()
> {
>     my_any t = s{};
>     t = t(t);
> }
>

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Loading...