简体   繁体   中英

Moving legacy C++ standard library from GNU version to that in LLVM

I have a Mac app which is built with the Nano library, which is no longer being developed. It uses the GNU standard C++ library, but that is not usable with Xcode 10 or later, so I'm trying to update the bits that need it to work with the version built into LLVM.

I've managed to solve some issues, but there is a problem with functors.

In the base class for functors, NFunctor, there are various macros so that the class is defined as:

typedef nfunctor<void (void)>   NFunctor;

That ends up (I think, as preprocessing fails) as:

typedef std::function<void (void)> NFunctor;

In the original code, it came out as:

typedef std::tr1::function<void (void)> NFunctor;

Compiling fails with an error:

error: no template named 'function' in namespace 'std'

In the GNU library, there's a definition:

 template<typename _Signature>
    class function;

In the standard library, there's

template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined

but also

template<class _Rp, class ..._ArgTypes>
class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
    : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
      public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>

Further, looking at the Wikipedia page Functional(C++), it has an example:

  /* A function wrapper generated by std::bind().
   * Pass a pre-defined parameter when binding.
   */
  std::function<void(void)> func_d = std::bind(PrintValue<std::string>, "PI is");
  func_d();

which looks like what I'm aiming to produce.

So my eventual question is what should be done to replace the old TR1 version of function in this code?

It turned out to be a matter of compiler settings. Setting the language dialect to C++14 or C++17 (or the GNU variants) seems to have fixed things.

I've got past problems with the standard library, and now I'll have to deal with other questions as they arise (still not completely working).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM