mercredi 30 septembre 2015

Access to different struct with same name

I'm trying to implement a workaround for boost versions that cause problems with scoped enums on linking in C++11 mode: See http://ift.tt/1H7SdWl and http://ift.tt/1haLphx

The problem is simply: Most pre-distributed boost libs expose (namespaces stripped):
detail::copy_file(path const&, path const&, copy_option::enum_type, error_code*)
But C++11 compilation tries to find:
detail::copy_file(path const&, path const&, copy_option, error_code*)
due to the fact, that C++98 boost uses emulated scoped enums, instead of the C++11 ones.

I though I might be able to write an adapter for that put it into an own object file and link that into the program, but I failed with my naive approach:

#define copy_option native_copy_option__
#include <boost/filesystem/operations.hpp>
#undef copy_option

namespace boost {
namespace filesystem {

    struct copy_option{
        enum enum_type{none, fail_if_exists = none, overwrite_if_exists};
    };

namespace detail {

    void copy_file(const path& from, const path& to, copy_option::enum_type option, system::error_code* ec=0);

    using copy_option = native_copy_option__;
    void copy_file(const path& from, const path& to, copy_option option, system::error_code* ec)
    {
        copy_file(from, to, static_cast<boost::filesystem::copy_option::enum_type>(option), ec);
    }

}  // namespace detail
}  // namespace filesystem
}  // namespace boost

The problem is: I need to define a function with the C++11 enum in the signature but also declare a function with the C++98 enum which has the same name.

Is this somehow possible?

Aucun commentaire:

Enregistrer un commentaire