Skip to content

__cplusplus value should not be used to decide for std::unique_ptr #350

@Dani-Hub

Description

@Dani-Hub

Both json_writer.cpp and json_reader.cpp currently use the following preprocessor test to decide whether to use std::unique_ptr instead of std::auto_ptr:

#if __cplusplus >= 201103L

This heuristics isn't sufficient for currently existing popular C++ Standard Libraries. E.g. the Dinkumware library provided with Visual Studio 2015 does provide a conforming std::unique_ptr implementation, but the underlying compiler still reports a __cplusplus value of 199711, because of a conservative policy signaling that not all parts of the C++ 11 Standard are provided. Nonetheless VS 2015 has an extremely good conformance for practical purposes, therefore I recommend to not rely alone on the value of __cplusplus which is not necessarily a sign that std::unique_ptr is available or not.

I would recommend to consider a more robust characteristics to accept Libraries (such as Dinkumware) providing a valid std::unique_ptr, especially because as of C++11 the type std::auto_ptr has been formally deprecated and as of C++14 it has been completely removed from the Standard Library specification. Now Dinkumware officially allows users to disable this type by defining a the macro _HAS_AUTO_PTR_ETC equal to 0 (as described here: http://blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17-features-in-vs-2015-rc.aspx) to respect this.

Boost evaluates whether _CPPLIB_VER is either not defined or has a value less than 520 for this (plus some additional preprocessor gymnastics) which seems to be more reasonable way. I'm willing to contribute such a heuristics that would better support Visual Studio 2015 and beyond.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions