Suggestion for C++ migration tool: tr1 removal

TR1 was a very successful add-on to C++03.
However, most (if not all) of the bits of TR1 are now part of the C++11 standard.

Some c++11 standard library implementations include the TR1 features (libstdc++, Dinkumware), while others (libc++) do not.

I think it would be great if the c++11 migration tool "migrated" away from using tr1 features in favor of using the ones in std.

For example:

    #include <tr1/unordered_map>
    int main()
    {
        std::tr1::unordered_map <int, int> ma;
        std::cout << ma.size () << std::endl;
        return 0;
    }

should be rewritten to:

    #include <unordered_map>
    int main()
    {
        std::unordered_map <int, int> ma;
        std::cout << ma.size () << std::endl;
        return 0;
    }

and so on.

Comments?

-- Marshall

Sounds good! If you are not going to work on it in immediate future,
please put this text in
http://clang.llvm.org/docs/ClangTools.html#ideas-for-new-tools

Dmitri

Would you log an enhancement in bugzilla too?

TR1/nonTR1 plagues our code base. I would warmly welcome consistency.

#if defined(OS_APPLE) || defined(CXX_CLANG)
# include <tr1/memory>
using std::tr1::shared_ptr;
#else
# include <memory>
using std::shared_ptr;
#endif

Total pollution in 2013.

Jeff

I went ahead and committed this as r176423, to ensure that it does not get lost.

Dmitri

Minor nit-pick:

#if defined(OS_APPLE) || defined(CXX_CLANG)

This should check the standard library type / version, not a compiler.

If it worked reliably, I would. Clang and __GNUC__ is a perfect
example. Confer: http://www.google.com/search?q=clang+GNUC+bug.

I find it easier to pick up OS'es and Compilers (including versions as
required), and work around their personalities. Using OS/Compilers,
I've got code that cross compiles cleanly on Windows, Mac OS, and
Linux using Clang, Comeau, ICC/ICPC, VC++. And the programs are
correct.

Jeff

#if defined(OS_APPLE) || defined(CXX_CLANG)

This should check the standard library type / version, not a compiler.

If it worked reliably, I would. Clang and __GNUC__ is a perfect
example. Confer: http://www.google.com/search?q=clang+GNUC+bug.

Surely, you should not use __GNUC__ to distinguish between libc++ and
libstdc++. Here, I will be out of luck if I, for example, use gcc 4.4
on MacOS (compiled via MacPorts).

Anyway, Marshall already written a note, how the check should look like:
http://marshall.calepin.co/c-and-xcode-46.html

And more generally:

   http://sourceforge.net/p/predef/wiki/Libraries/

I have started a "real blog", and moved that post to:
  http://cplusplusmusings.wordpress.com/2013/02/26/c-and-xcode-4-6/

Updates will appear there, rather than at calepin.co

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

I think it would be great if the c++11 migration tool "migrated" away from using tr1 features in favor of using the ones in std.

Sounds good! If you are not going to work on it in immediate future,
please put this text in
http://clang.llvm.org/docs/ClangTools.html#ideas-for-new-tools

I went ahead and committed this as r176423, to ensure that it does not get lost.

So … how would you use the rewriting framework to change include file names?

For example,
change: #include <tr1/unordered_map>

Or the more general - how do you change preprocessor directives?

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

>>> I think it would be great if the c++11 migration tool "migrated" away
from using tr1 features in favor of using the ones in std.
>>
>> Sounds good! If you are not going to work on it in immediate future,
>> please put this text in
>> http://clang.llvm.org/docs/ClangTools.html#ideas-for-new-tools
>
> I went ahead and committed this as r176423, to ensure that it does not
get lost.

So … how would you use the rewriting framework to change include file
names?

For example,
change: #include <tr1/unordered_map>
to: #include <unordered_map>

Or the more general - how do you change preprocessor directives?

We currently search for the text, and create replacements based on that.

Cheers,
/Manuel

http://llvm.org/bugs/show_bug.cgi?id=15449

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki