stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: Another potential hole in the tuple specs
Date Mon, 07 Jul 2008 23:44:01 GMT
Eric Lemings wrote:
>  
> 
> Here's another potential problem with the tuple spec.  The latest draft
> declares std::ignore like so:
>  
> 	namespace std {
> 	    const /*unspecified*/ ignore;
> 	}
>  
> The type of std::ignore is implementation-defined but for illustration,
> let's say its defined like this:
> 
> 	namespace std {
> 
> 	struct _Ignore
> 	{
> 	    template <class _Type>
> 	    _Ignore& operator= (const _Type& value) { return *this; }
> 	};
> 
> 	const _Ignore ignore = _Ignore ();
> 
> 	} // namespace std
> 
> (The need for the operator will become evident shortly.)
> 
> Here's how the tie() function is specified, quoting from the standard:
> 
> 	  template<class... Types}
> 	  tuple<Types&...> tie(Types&... t);
> 
> 	4 Returns: tuple<Types&>(t...). When an argument in t is ignore,
> assigning any value to the corresponding
> 	  tuple element has no effect.
> 
> 	5 [ Example: tie functions allow one to create tuples that
> unpack tuples into variables. ignore can be used for
> 	    elements that are not needed:
> 
> 		int i; std::string s;
> 		tie(i, ignore, s) = make_tuple(42, 3.14, "C++");
> 		// i == 42, s == "C++"
> 
> 	  -end example ]
> 
> In the example, the return type of the call to the tie() function is
> std::tuple<int&, const std::_Ignore&, std::string&>.  Note that the
> second element type in the tuple is a constant reference.  Regardless of
> the implementation-defined type of std::ignore, isn't it impossible to
> change the value of a constant reference once initialized?  This would
> mean the example shown above is ill-formed I believe.

You mean because tie(i, ignore, s) = make_tuple(42, 3.14, "C++")
must assign 3.14 to std::ignore? Would declaring the assignment
operator cost be a way to make it work?

Martin



Mime
View raw message