is this legal c++0x?

  • Permalink
  • submit to reddit
  • Email
  • Follow


If subscript operator is legal as non-member function in c++0x, could
we write?



template <typename...Types, int N>
auto operator[](tuple<Types...> && tup, int n = N) -> constexpr
decltype(get<N>(tup))
{
	return get<N>(tup);
}


is this legal c++0x? Because if it is. We could write.

tuple<int, float, string> mytuple;

mytuple[2] = 12;

and expressions in array-like notation.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply german 5/9/2009 11:04:01 AM

See related articles to this posting


german diago wrote:
> If subscript operator is legal as non-member function in c++0x, could
> we write?
> 
> 
> 
> template <typename...Types, int N>
> auto operator[](tuple<Types...> && tup, int n = N) -> constexpr
> decltype(get<N>(tup))
> {
> 	return get<N>(tup);
> }
> 
> 
> is this legal c++0x? Because if it is. We could write.
> 
> tuple<int, float, string> mytuple;
> 
> mytuple[2] = 12;

Sorry, but N cannot be deduced in this way.

Furthermore, we would get functions with weird signatures,
since default values are not part of it.

-- 
Dragan

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply Dragan 5/15/2009 5:43:39 AM
comp.lang.c++.moderated 10625 articles. 8 followers. Post

1 Replies
165 Views

Similar Articles

[PageSpeed] 31


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Is this legal c++0x
If subscript operator is legal as non-member function in c++0x, could we write? template <typename...Types, int N> auto operator[](tuple<Types...> && tup, int n = N) -> constexpr decltype(get<N>(tup)) { return get<N>(tup); } is this legal c++0x? Because if it is, we could write: tuple<int, float, string> mytuple; mytuple[2] = 12.6f; and expressions in array-like notation. -- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.ed...

[C++0x] Is these 2 legal?
Example 1: int main() { int x = 5; int &&y = x; } Example 2: int &&move(int &&x) { return x; } int main() { int x = 5; int &&y = move(x); } On 4 mar, 10:21, Michael Tsang <mikl...@gmail.com> wrote: > Example 1: > > int main() { > =A0 int x =3D 5; > =A0 int &&y =3D x; > } Yes. > > Example 2: > > int &&move(int &&x) { > =A0 return x; > } > > int main() { > =A0 int x =3D 5; > =A0 int &&y =3D move(x); > } Yes. -- Micha...

NonTypeTemplateParameterType c++0x, legal user-defined template parameters?
Hello. Looking at the standard, I have no clear idea if user-defined literals which are constexpr can be used as template parameters. Can this be done? class MyStr { MyClass operator ""_str(...); //... }; concept_map NonTypeTemplateParameterType<MyClass> {}; And now, could I do something like this? register_type<"Class"_str>([] { return new Class; }); Thanks in advance. -- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu] [ ...

Is C# really "better" than C++ or C++0x? How about objective-C?
Microsoft thinks C++ is obsolete and C# is "the future". Apple thinks the same for Objective-C. IMO this is all nonsense. What do you think about this? How "better" really they are? And what about C++0x? On Sun, 17 Apr 2011 16:58:37 +0200, "A" <a@a.a> wrote: >Microsoft thinks C++ is obsolete and C# is "the future". Apple thinks the >same for Objective-C. > >IMO this is all nonsense. I agree. > >What do you think about this? How "better" really they are? And what about >C++0x? > Companies like Microsoft ...

Help needed with a C++ syntax (legal in C, but not C++)
Greetings, I'm trying to use a vender-supplied API in my C++ program. The vender's API is in C and it contains something similar to: type int INT; struct S { int i; double INT; /* OK in C, not C++ */ } According to a C/C++ book (C, A reference manual by S Harbison and G. Steele JR), the above struct is actually legal in C, as typedef names can be redeclared as objects in inner scopes. However, in C++ it is not permitted to do so within a structure or union -- which are scopes -- if the original typedef name has been used in the structure or union already. The problem I'm f...

C++0x = C++ 2003?
Is this just pre-marketing or is it real? <url: http://webstore.ansi.org/ansidocstore/product.asp?sku=ISO%2FIEC+14882%3A2003> If it's real, what are the main differences from the 1998 (late 1997) version? Is it worth shelling out $273.00 for? (Admission: I never found the previous version's $18 price to be reasonable enough, given the impenetrable nature of the text, the lack of hyperlinks, dictionary, etc., to _buy_ the thing...) [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] In article...

C++0x: The future of C++
Nice article on the new C++ 11 standard. C++0x: The future of C++: http://www.cprogramming.com/c++11/what-is-c++0x.html Lynn ...

On the organisation of the C++ standards committee for C++ 0x
Hello, Could someone clarify the structure, with respect to projects, of the C++ standards committee. My understanding is that there are 3 "areas": - C++ core language extension proposals - C++ library extension proposals - C++ performance issues Further, that TR1 slices through the first two projects and that the bulk of the work for TR2 deals with library extensions. --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before po...

compilers supporting the new c++ thread (c++0x)
Hello, I would like to know which compilers support the new c++0x thread model. Thank, Bob Bob <bobbe@gmail.com> writes: > I would like to know which compilers support the new > c++0x thread model. g++ has been incrementally adding support for C++0x threads since g++4.4. g++4.4 has basic support for thread launching, and mutexes and condvars; g++4.5 adds some support for futures, but the library still doesn't cover everything. My just::thread library provides full support of the thread library from the FCD for MSVC 2008, MSVC 2010, g++ 4.3 and g++ 4.4....

Is this legal C++?
Below is a small piece of code that I'm curious about. It is a recursive template function that accepts a vector of any dimension. The function returns the dimension of the vector passed into it. It seems that the typename parameter "A" is allowed to be a template itself. This code doesn't give me any warnings, but Is this legit C+ +? I had never seen this before, and I have just recently discovered this by accident. If this is indeed legal C++, this is a very nice way for a function to accept N-dimensional vectors. // file.cpp #include <iostream> #include <v...

C++0x or... ?
I have an opportunity to talk with some students next week about some of the new features in the upcoming C++ standard (this is just going to be a short presentation... not a whole course or a serious seminar). I'm wondering now what to call this new version of C++. I know it's been informally referred to as "C++0x" for a while but here it is 2009 and, as far as I know, the standard is not yet official. Is the new standard really going to be C++ 2010? Should I be calling it C++1x? Is there some other name that I should be using that would be more appropriate? Sorry fo...

Modern c++, c++0x (g++ 4.4 and above) in DJGPP
Hi, are there ay real chances to have DJGPP based on g++ 4.3, 4.4 etc (so, soon with good c++0x support)? That would allow to build most modern c++ programs using djgpp. Hi, On Jul 26, 5:37=A0am, Rafa=B3 <newsgr...@limcore.com.invalid> wrote: > > are there ay real chances to have DJGPP based on g++ 4.3, 4.4 etc (so, so= on > with good c++0x support)? > > That would allow to build most modern c++ programs using djgpp. I'm no expert (by far), but since I'm already here, I'll have to do! ;-) First of all, Andris has indeed built test builds of 4.3.0 an...

legal c++?
template < typename T1, typename T2, T2 T1::*x > struct test1 { }; struct test2 { int x; typedef test1<test2, int, &test2::x> type; }; int main() { test2 t2; test2::type t1; } Compiles with g++ and comeau online (warnings about unused variables) but MS compiler gives error: error C2327: 'test2::x' : is not a type name, static, or enumerator e:\playground_projects\testing_ground\testing_ground\testing_ground.cpp 14 1 Error error C2065: 'x' : undeclared identifier e:\playground_projects\testing_ground\testing_ground\testing_ground.cpp 14 2 Er...

Is this legal C?
This was asked in a C test. Is the following code legal C? Is it legal in C90? C99? #define main() int main #define mainbody () { return 0; } mainbody Max wrote: > This was asked in a C test. Is the following code legal C? > Is it legal in C90? C99? Yes. Yes. > #define main() > int main > #define mainbody () { return 0; } > mainbody It's as legal as int main(){return 0;} is. -- pete pete <pfiland@mindspring.com> writes: > Max wrote: > > This was asked in a C test. Is the following code legal C? > > Is it legal in C90? C99? > > ...

C++0x
Which C++0x proposal deals with extending algorithms such as sort, find or count to use concepts, so that we no longer have to write sort(c.begin(), c.end()) but can write sort(c) instead? Is it the concepts proposal itself? Are there proposals for any other improvements to std library related to concepts? thanks, Marcin -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] On 2008-05-17 10:28, Marcin Kalicinski wrote: > Which C++0x proposal deals with extending algorithms such as sort, find or > c...

[C++0x or later] C# Properties, inner classes and CRTP
I want to propose and discuss the following new language features that, as a side effect, allow an easy and flexible definition of C# like properties (that is even better than C#) in C++ classes. QUICK SUMMARY I propose to introduce - A new syntax for anonymous inner classes that derive from a base class. - The keyword "nested", that tells a nested class to store a hidden reference to the enclosing object (like in java) - The keyword "enclosing_object" using either the hidden reference, or a mechanism equivalent to the "offsetof" macro trick de...

is this legal C++? (on "Modern C++" style templatized policies)
I've been reading Alexandrescu's "Modern C++" and trying to experiment with templatized policies. Unfortunately my Forte 6.1 compiler on Solaris 2.8 doesn't support template template parameters. Alexandrescu suggests implementing policy classes using ordinary classes with template member functions to get round this, but mentions that the approach is harder to use than implementations with template template parameters. I had the thought of trying a slight variant of the template member function approach that might be easier to use, being more similar to the template ...

C++ danger to break due to its weight, fragmentation danger
I would like to see your views on these. C++98 is already a large language since it supports 4 paradigms and each one is supported well, with optimal space and time efficiency. And this is excellent. From the few things that i have read about C++0x, in addition to some C99... features (actually some other term comes in my mind for this instinctively, but it is another subject for discussion), there is library expansion with new facilities, some of them *not supported directly by language constructs* (= exotic) like networking. Also not all of the new features will be required by the standar...

C++ danger to break due to its weight, fragmentation danger
I would like to see your views on these. C++98 is already a large language since it supports 4 paradigms and each one is supported well, with optimal space and time efficiency. And this is excellent. >From the few things that i have read about C++0x, in addition to some C99... features (actually some other term comes in my mind for this instinctively, but it is another subject for discussion), there is library expansion with new facilities, some of them *not supported directly by language constructs* (= exotic) like networking. Also not all of the new features will be require...

Why A Big Difference between C++98 and C++0x on a local type as a template-argument?
Dear all, C++98 14.3.1 explicitly says as follows: "A local type, a type with no linkage, an unnamed type or a type compunded from any of these types shall not be used as a template- argument for a template type-parameter." And the Standard also immediately gives an example: /*-- Source Code Begin --*/ template <class T> class X {}; void f() { struct S {}; X<S> x3; // error: local type used as template-argument } /*-- Source Code End --*/ Nevertheless, the source code should can be correctly compiled by Visual C++. Moreover, C++0x 14.4.1 explicitly says d...

Why A Big Difference between C++98 and C++0x on a local type as a template-argument?
Dear all, C++98 14.3.1 explicitly says as follows: "A local type, a type with no linkage, an unnamed type or a type compunded from any of these types shall not be used as a template- argument for a template type-parameter." And the Standard also immediately gives an example: /*-- Source Code Begin --*/ template <class T> class X {}; void f() { struct S {}; X<S> x3; // error: local type used as template-argument } /*-- Source Code End --*/ Nevertheless, the source code should can be correctly compiled by Visual C++. Moreover, C++0...

C++0x "auto" equivalence in non-0x? (function needs to return undetermined type value)
What I want to do is, template <typename T> void process(const T & value); UndeterminedType generate(); "generate" may return value in various types, which is unknown when it's called. What's determined is that all types are already known and defined. So I know "generate" can return a value in type A, B or C, but I don't know which one it exactly is. The result from "generate" is only used to feed "process", I don't need to store it. But it will be good if I can store it. Seems "auto" keyword in C++0x is introduce...

C++0x fluidity
Suppose I started doing my stuff in the dialect that current GCC calls C++0x. Am I likely to have big rewrites coming my way when the standard is finalized? Martin -- Quidquid latine scriptum est, altum videtur. On 8 Mrz., 15:34, Martin Eisenberg <martin.eisenb...@udo.edu> wrote: > Suppose I started doing my stuff in the dialect that current GCC > calls C++0x. Am I likely to have big rewrites coming my way when the > standard is finalized? I would say it depends on the features you think about and their maturity. For example, the details of the rvalue reference semantic...

The design of C++0x
http://www.research.att.com/~bs/rules.pdf -- If our hypothesis is about anything and not about some one or more particular things, then our deductions constitute mathematics. Thus mathematics may be defined as the subject in which we never know what we are talking about, nor whether what we are saying is true.-Bertrand Russell Published long ago, what? ben "Steven T. Hatton" <chattengau@germania.sup> wrote in message news:BumdneNF1YB1eCbfRVn-qg@speakeasy.net... > http://www.research.att.com/~bs/rules.pdf > -- > If our hypothesis is about anything and not about some...