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 10665 articles. 10 followers. Post

1 Replies
196 Views

Similar Articles

[PageSpeed] 22


  • 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...

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 ...

Better C/C++ Than C/C++?
I am looking for a good systems programming language that can be used instead of C/C++. My qualifications for the language are: * mature compiler(s) that produce native-code binaries (for Windows) * open source - preferable, but not 100% necessary Thanks, Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) Ocaml, D, cyclone, Eiffel, Beta >...

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] [ ...

jython and C-c C-c
How do I get C-c C-c to work with jython? I have the jpython command set to jython, and I can start the interpreter with C-C ! and then use C-c C-c, but this is rather frustrating. If I try to use C-c C-c without first starting the interpreter in another window I get wrong type argument: sequencep, jpython Thanks, Dave Cook ...

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...

c------->c++ and c++------>c
We can write c program in turbo c++ editor.But reverse is not true why? i.e The program will not compile if u write c++ program in turbo c editor vim wrote: > We can write c program in turbo c++ editor.But reverse is not true why? > i.e The program will not compile if u write c++ program in turbo c > editor This isn't about C; this is about some editor. Why the fircone should /we/ know? Ask in a relevant group. [And /why/, in an editor specialised to some specific programming languages, would you expect it to compile a /different/ one? Would you expect turbo perl to compi...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

C as a Subset of C++ (or C++ as a superset of C)
Isn't it a lame use of human time and effort to maintain completely separate C and C++ standards? As in the words of Betty White about Facebook: "It seems like an incredible waste of time". Why don't the two standards groups get together and agree on a common specification for the ground which both standards cover? There would still be two separate standards, but they'd both be exactly the same for the common ground. The common ground document could be referred to by both standards instead of being maintained by both groups in individual efforts resulting in...

C/C++ in MATALB or MATLAB in C/C++?
Hi I've been asking on the net how to use MEX properly so that I can use C/C++ in MATLAB, but information is not forthcoming. There seems to be a lot on using MATLAB in C/C++ but not the other way around. I understand Mathworks is trying very hard to sell the Matlab Compiler, but even so, why is it SO hard to get information about MEX? Or is it that I've missed something very fundamental, meaning that I'm struggling over something that is actually quite easy? Any thoughts and info would be great. Thanks BullDog BullDog wrote: > Hi > > I've been asking on the net ...

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....

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! In article <1120963701.862698.160260@g14g2000cwa.googlegroups.com>, Throne Software <mail@thronesoftware.com> writes >Throne Software has opened up C, C++ and C# Forums at: > >http://www.thronesoftware.com/forum/ > >Join us! Why? The beauty of news groups is that they come to me I don't have to go to them. Also all the people who have been around a while know what they are doing and are here. I noticed that there are some C and C++ Forums on another system...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! Throne Software wrote: > Throne Software has opened up C, C++ and C# Forums at: > > http://www.thronesoftware.com/forum/ For all of your forums newsgroups already exist. > Join us! Why? Don't see any reason to support your marketing. ...

c,c++,obj-c
Of the 3 languages titled in this post is c++ older than obj-c ? Would someone experienced in C be able to dive right into C++ rather than obj-c ? Java is out for me now except applet programming I think I'm going to go with just C and C++. Bill Bill Cunningham wrote: > Of the 3 languages titled in this post is c++ older than obj-c ? Why does that matter? Do you want to use an old language? Try Fortran or LISP. > Would > someone experienced in C be able to dive right into C++ rather than > obj-c ? Not quite dive in, at least not into the OO parts of C++. ...

C,, C++, Java, C#
I come from C,C++,Java and C#. What can SmallTalk do for me and for what cost? Regarding the Squeak thing, it's interesting though confusing. Is it an IDE? Why are the menus so wacky? "DM McGowan II" <nospam@nospam.net> wrote in message news:PLednX2vnLd11IncRVn-rA@comcast.com... > I come from C,C++,Java and C#. What can SmallTalk do for me ...? Ask not what Smalltalk can do for, but what can you do with Smalltalk. :-) In very few words, it significantly reduces time to market, while enhancig the development experience. This is because: 1. It...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! ...

C++ or C?
I am new to MPI and have a basic understanding of C and C++. So I was wondering if any of you guys with experience in using MPI had any pointers with regards choosing either C or C++. I intend to use MPI in parallelizing code I have that was written in Java. So obviously the Java code it is heavly object orientated. With regards parallelizing it; right now I think it will mainly be a Master-Slave style of design with no inter-process communication needed once the master has sent the work to the slave. Most, if not all, of my communications will involve simply sending a large object from the ...

c++/c
hi i have been recently told that there is no exception handling ic c+ +.?? as far as i remember i have read, it has. also java has exception handling for sure but there we can use finally also which we cant use in c ++. what other differences do we have in the two languages c++ and java in exception handling. and which one is better? rupika wrote: > > i have been recently told that there is no exception handling ic > c++.?? You should ask about C in comp.lang.c, about C++ in comp.lang.c++. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home...

C++ to C
Are there any open source C++ compilers that will produce C code? I understand the first C++ compilers operated this way. On Mon, 27 Oct 2003 23:07:19 GMT, "Bootstrap Bill" <wrcousert@yahoo.com> wrote in comp.lang.c: > Are there any open source C++ compilers that will produce C code? I > understand the first C++ compilers operated this way. C++ compilers are off-topic in comp.lang.c. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-...

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...