Std :: function has no name named 'target'

I am trying to keep a list of unique function pointers. The obvious wrapper for pure pointers is std :: function .

As it turned out, std::function

it cannot be compared .

Then a simple comparison of the original pointers should work, right? Possibly, but I am getting the following error for the following code. My compiler is gcc 4.7.2. Is this something that hasn't been implemented back in 2012?

    std::function<void(bool)> f;
    void(*p)(bool) = f.target<void(*)(bool)>();

      

error: 'class std :: function' has no name named 'target'


Here is the relevant question, apart from the title:

#ifdef __GXX_RTTI
      // [3.7.2.5] function target access
      /**
       *  @brief Determine the type of the target of this function object
       *  wrapper.
       *
       *  @returns the type identifier of the target function object, or
       *  @c typeid(void) if @c !(bool)*this.
       *
       *  This function will not throw an %exception.
       */
      const type_info& target_type() const noexcept;

      /**
       *  @brief Access the stored target function object.
       *
       *  @return Returns a pointer to the stored target function object,
       *  if @c typeid(Functor).equals(target_type()); otherwise, a NULL
       *  pointer.
       *
       * This function will not throw an %exception.
       */
      template<typename _Functor>       _Functor* target() noexcept;

      /// @overload
      template<typename _Functor> const _Functor* target() const noexcept;
#endif

      

+3


source to share


1 answer


I had this problem too. RTTI must be enabled in the compiler flags. I had -fno-rtti

in the compiler flags.



+1


source







All Articles