• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [ Maybe offtopic ] on c++ namespace aliasing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ Maybe offtopic ] on c++ namespace aliasing


  • Subject: Re: [ Maybe offtopic ] on c++ namespace aliasing
  • From: Pascal Bourguignon <email@hidden>
  • Date: Mon, 02 Jan 2017 18:31:10 +0100


On 2 Jan 2017, at 15:11, Ariel Feinerman <email@hidden> wrote:

I tried to figure out how to write a namespace compatible c++ code between various standard versions, and find out that it is impossible. Are the any Xcode tools or scripts (possibly, clang cpecific) that can do the trick? 

I wish use everywhere std::some_class which can expand to boost:: or custom_namespace::some_class if compiler uses older c++ version.

Thank you in advance.

Just #define it!


[pjb@despina :0.0 cpp]$ for f in namespace.cc main.cc ; do printf '=== %s ====================\n' $f ; cat $f ; done
=== namespace.cc ====================
// -*- mode:c++ -*-

#include <iostream>
#ifndef s
#define ss(x) s(x)
#define s(x) #x
#endif

namespace MYNAMESPACE {

    class Greeter{
    public:
        void sayHello(){
            std::cout<<"Hello "<<ss(MYNAMESPACE)<<"!"<<std::endl;
        }
    };

}


=== main.cc ====================

#define MYNAMESPACE foo
#include "namespace.cc"
#undef MYNAMESPACE

#define MYNAMESPACE bar
#include "namespace.cc"
#undef MYNAMESPACE



int main(){
    foo::Greeter foo;
    bar::Greeter bar;
    foo.sayHello();
    bar.sayHello();
    return 0;
}
[pjb@despina :0.0 cpp]$ SRC=""http://main.cc" class="">main.cc" ; EXE="namespace" ; g++ -I. -L. -g3 -ggdb3 -o ${EXE} ${SRC} &&  ./${EXE} && echo status = $?
Hello foo!
Hello bar!
status = 0
[pjb@despina :0.0 cpp]$ 

-- 
__Pascal J. Bourguignon__



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >[ Maybe offtopic ] on c++ namespace aliasing (From: Ariel Feinerman <email@hidden>)

  • Prev by Date: Re: Where are all the PDF files for developer documentation?
  • Next by Date: Re: Creating a bunble with XCode.
  • Previous by thread: [ Maybe offtopic ] on c++ namespace aliasing
  • Next by thread: Re: Creating a bunble with XCode.
  • Index(es):
    • Date
    • Thread