Automatically rewrite C ++ 11 auto keyword in derived types

Perhaps a strange question, but is there any software that, given a bunch of C ++ 11 code, outputs all types of automatic typed variables and rewrites the code with these derived types? And also for initializer lists?

We believe that we would like to provide a backward compatible version of our code (not C ++ 11), mainly for portability using osx. Lists of automatic printing and initialization are the functions that we use the most because they make the code more readable, but deleting them manually is non-go. Since this is really what the compiler does with automatic typed variables, doesn't it seem too far-fetched?

+6
source share
3 answers

See BOOST_AUTO and / or BOOST_TYPEOF

You can replace

auto x = foo(); 

from

  BOOS_AUTO(x, foo()); 

If you want to "manage" an ad, you will have to resort to BOOST_TYPEOF. Note that both macros have several options that you want to learn more about.

+3
source

If you can use Boost, you can look at boost :: typeof . It will not do what auto does, but in most cases it can be automatically replaced using the regex-with-capture search.

+2
source

Sounds like a feature for the Eclipse CDT refactoring plugin (I actually suggested this to my students some time ago). Maybe next time I can find a team to create one. However, the Eclipse CDT information may not be good enough to always determine the right things.

For some initiator lists, for example, to populate a vector, boost :: assign may be a replacement. Our Mockator mock object infrastructure uses them for C ++ 03 instead of C ++ 11 initialization lists.

You should not be afraid of Boost libraries, at least not those that are included only in the header. Those who have separate parts can be a little troubles for proper setup (recently, the situation has improved).

+1
source

Source: https://habr.com/ru/post/909617/


All Articles