From: Jeff Squyres Date: January 18, 2008 7:23:12 PM CST To: mpi-21@XXXXXXXXXXXXX Subject: Re: [mpi-21] const MPI C++ handles Reply-To: mpi-21@XXXXXXXXXXXXX On Jan 18, 2008, at 8:00 PM, Erez Haba wrote: >> Just trying to be cautious: would there ever be a reason to have a >> non- >> const version of the Set_* functions? > > Yes, if the impl caches info in its own objects and change it when > the Set_* function is called. (but then it can use the mutable > keyword :)) You're talking about a pure C++ implementation, right? If an implementation simply caches a C handle and invokes the underlying C MPI function, it doesn't need to be const -- perhaps something like this (where mpi_comm is the C handle cached in the MPI::Comm class): inline void MPI::Comm::Set_name(const char* comm_name) const { (void) MPI_Comm_set_name(mpi_comm, const_cast(comm_name)); } Regardless, MPI::Comm is required to be a handle, not the actual underlying MPI object. So stuff like this is ok: MPI::Intracomm foo = MPI::COMM_WORLD; foo.Send(...); MPI::COMM_WORLD.Send(...); Both sends will be the same communicator. Hence, the internal cached reference to the underlying object must always be immutable (allowing the function to be const) -- it's the underlying object that must be mutable. Right? > > Thanks, > .Erez > > -----Original Message----- > From: owner-mpi-21@mpi-forum.org [mailto:owner-mpi-21@mpi- > forum.org] On Behalf Of Jeff Squyres > Sent: Friday, January 18, 2008 11:19 AM > To: mpi-21@mpi-forum.org > Subject: Re: [mpi-21] const MPI C++ handles > > On Jan 18, 2008, at 2:11 PM, Erez Haba wrote: > >> I looked up this issue and did not find a C++ *standard* that spans >> that many platforms and compilers. >> >> The ISO C++ 98 standard itself does have libraries, but they provide >> the headers which are less ambiguous. (including various const >> values (like INT_MAX)) (think ABI :)) > > Hah! Surely you're not implying that C++ compilers produce code that > is ABI-compatible with other C++ compilers? :-D > >> I agree that we'll need to enable the recommendation in the standard >> interface. We'll need to agree that the semantic of changing the >> underlying MPI handle is not changing the object (and thus can >> define the method as const). >> >> I don't think you'll need an overloaded function for the Set_* >> functions; const methods are good for non const objects. > > Good point -- a const method will match a corresponding non-const > (*this). > > Just trying to be cautious: would there ever be a reason to have a > non- > const version of the Set_* functions? > > -- > Jeff Squyres > Cisco Systems > -- Jeff Squyres Cisco Systems