Does anyone have information on using operator""? - c++

Bjarne Stroustrup gave a keynote presentation today for the Going Native 2012 conference. In his presentation, he discussed the issue of enforcing correct units. His elegant (IMHO) solution to this involved using an operator I have never heard of before: operator"". Using this operator, he was able to write C++ code that looked like this:
ratio = 100m / 1s;
Where operator""m(...) and operator""s(...) were defined.
Does anyone know of any documentation regarding how to actually use this operator (or even if any modern C++ compilers support it)? I tried searching online, but had no luck. Any help would be greatly appreciated.

The syntax you'd be looking for is "user-defined literals" which is a feature of C++11.
g++ versions 4.7 and better support this feature.
Here is some documentation describing the use of that operator overload:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf
Also see the excellent link Xeo provides in the comments to your question.

Currently the best documentation is probably in the standard itself. You can get the latest version from the commitee's site. According to gcc's site it will be in the next revision of gcc (gcc-4.7). You should be able to test it when building gcc from the SVN repository.

Related

How can I run the custom version of C++03 in Xcode?

For a school assignment, I am required to use C++ version 03. I have a Mac, and I was told to use Xcode by my instructor.
After a bit of research, I found the place on where to change the version of C++ that is being used. As shown in the image, the version C++03 is not available. I tried typing "C++03 [-std=c++03]" in the "Other..." option, but my build failed.
I tried searching around on here and online, but I couldn't find anything that provided a solution.
Can someone please give me some guidance on what to do here? I am entirely new to C++, and I simply just want some help in being able to compile my code.
Thanks.
In Xcode on the Macintosh, to use C++03 (which should be nearly the same or identical with C++98), you can select the C++ Language Dialect > Other... > and type in c++03 (lowercase) in the field.
C++03 was more of a "big fix" to C++98, (q.v. this answer). It resolved some ambiguities in the language specification. Rather than being a significant new C++ standard.
You'll note that there are options like C++98 and GNU++98. The GNU++XX options enable several GNU extensions to the language, which if utilized means the code will not be strictly standard C++ compliant.
C++11 was a major change to the language. C++11 and later are sometimes referred to as "modern C++".

Accessing documentation on c++

I'm a novice programmer who just migrated from Python (on IDLE) to C++ and I'm finding it uncomfortable to know only a few "essential" methods of STL data structures. Is there something like the Python help() function in C++, or some other way to access digestible and concise documentation as regards the Standard Library?
Edit: To be clear, I am looking for a way to access documentation from my computer, preferably from within the IDE/compiler (I currently use and prefer g++ on Cygwin in Windows 7. I also have Code::Blocks, however). Please don't recommend books or mark this question as a duplicate of The Definitive C++ Book Guide and List.
This is the documentation I like the most : http://en.cppreference.com/w/
With a keyword for fast searching in Firefox, it is very efficient
In general Cplusplus.com helps very much.
Maybe the GNU C++
Library will also help.
You could also read the official C++
book by Bjarne Stroustrup.
http://cppreference.com
http://www.cplusplus.com
If you're on Mac OS, you can use the nice Dash which can integrate with editors or be used on its own. It supports the cppreference.com docs (instant offline indexed documentation).
If you're on Windows (Visual Studio) MSDN also provides STL docs.
As I'm on Linux I just use http://cppreference.com, but I'd like to have a good alternative (not Zeal) to Dash.

Which C/C++ compiler does Xcode use?

I just started to get my hands dirty with C/C++, and I am still getting my head around the different concepts (I've written mostly Java previously). I'd really like to know which C/C++ compiler is used and also which standard library is included. Also, I'd like to know where I can find the API documentation of the respective standard library (like the Java SE API docs).
For C++:
Xcode 4.6.2 uses the Clang C++ compiler frontend with LLVM as backend which is conform to the C++11 standart and uses libc++ as the standart library.
Here you can finde a apple presentation about libc++.
I'm not an XCode user, but it seems to be Apple's LLVM Compiler (by default) according to Apple's website: https://developer.apple.com/technologies/tools/. But, I guess, like any other IDE XCode does support other compilers like GCC. Also depends on your XCode version it seems: http://useyourloaf.com/blog/2011/03/21/compiler-options-in-xcode-gcc-or-llvm.html
Here's a question in SO that asks about the default compiler and the answer seems to have the code to find just that: In Xcode 4.5, what is "Compiler Default" for "C++ Standard Library" and "C++ Language Dialect"?
According to this post 4.6 uses clang instead of GCC for C++: http://cplusplusmusings.wordpress.com/2013/02/26/c-and-xcode-4-6/
P.S.: Googling does help ;)
I just noticed the second half of the question was never really answered:
... I'd like to know where I can find the API documentation of the
respective standard library ...
A simple Google search will reveal a wealth of information about this. Do note, however, that the "C++ Standard Library" is not the same thing as the "C Standard Library," so be careful of that when searching and reading. C++ has its roots in C, but the two have diverged to become separate languages that share a lot of commonality -- and a lot of hidden differences.
The canonical reference work regarding this is titled, appropriately enough, "The C++ Standard Library" by Nicolai M. Josuttis, published by Addison-Wesley. Many C++ programmers keep this on their bookshelves as a reference.
There is a good online reference for the library at https://cppreference.com/.
If you are interested in specifics of the LLVM implementation used by Apple's Xcode, see https://libcxx.llvm.org/ .
For a comprehensive list of the most highly recommended books and references for C++, Stack Overflow already has a very good FAQ regarding this: The Definitive C++ Book Guide and List.

may i know which C++compilers(online/free) supporting "inheriting constructors" feature in c++0x

May i know which C++compilers(online/free) supporting "inheriting constructors" feature in c++0x
N3290 draft :section 12.9 : Inheriting constructors
I tried with VS10,GCC 4.6.0 ..But i think it is not supporting ..(please confirm it.)
Please tell me which online compilers or Free compilers supporting .. This feature
http://wiki.apache.org/stdcxx/C++0xCompilerSupport
http://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx
I gooogled ..but i didn't get ..the correct info .. help me ?
So let's see:
google didn't find any compiler claiming to implement it;
overview pages don't list any compiler claiming to implement it;
clang, Comeau, GCC, and MSVC overview pages don't claim they implement it.
Seems consistent to me!
Maybe you do not like the answer you found, but it appears to be correct!
EDIT: Added clang and Comeau to the list, as suggested by comments.
NOTE: At some point in time, compilers will start to implement this. I won't update this answer when they do, so this answer might be out of date by now. A quick search on 10-feb-2012 didn't reveal any compilers that have implemented this yet, though.

What do I need to know about C++0x? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Where can I learn more about C++0x?
I am fairly familiar with C++03 but I still need to come to terms with C++0x so I would like to read some fairly digestible information on C++0x.
I have looked at the Wikipedia but I am on the look out for something that is more readable. So is there a book or series of blog entries that provide a nice introduction to the matarial?
There is a ton of stuff on this very site - some of the posts include very informative discussion. I would point you to Google but it's going to be more efficient to search in C++0x tagged posts here imo.
Here's a good one to start with, which includes indirection to Stroustrup's own summary. Scott Meyers has presentation materials on the topic here.
Check up on your favourite compiler's support for the new version. Microsoft VC10 support is summarized here. GCC info can be found here.
Official state of the standard for the language is available here. Evolution of the language is in many places tied to ongoing work in Boost. See here for some info on that.
Honestly my preference these days is to look here for 99% of needed info rather than resort to a book.
It's too early for a book. The standard isn't fixed yet.
Now, if you think wikipedia is hard to read, you might try Stroustrup's page about it. However it might seem harder to read to some.
There's a good tutorial on codeproject here for VC++. Even if you aren't using Visual Studio though it's still useful.
Learn whatever feature you would have loved having in C++98 in the first place. For me, it was variadic templates, lambda functions, decltype and other cool stuff.
If you still don't know what to learn first, maybe you should try to understand what issues from the C++98 are adressed. I say this because all the xvalue, move semantics and al stuff is quite heavy to grasp if you don't know what the problems were (and still are btw). This may imply learning some more C++98 first.
Then, you can always browse the Wikipedia article and look at whatever you find cool. Implementors don't provide all the features yet, so you'll look like a 5 year old staring at the front window of a toy store. This is a good reason to behave like one.
I really liked this series of blog posts by the Visual C++ Team Blog:
The Future of the C++ Language
Lambdas, auto, and static_assert: C++0x Features in VC10, Part 1
Rvalue References: C++0x Features in VC10, Part 2
decltype: C++0x Features in VC10, Part 3
I found the Overview of the New C++ (C++0x) book by Scott Meyers to be a good, detailed summary of the main features. It's more of a presentation with very detailed footnotes that an actual book, but it's still an excellent, short read.
I suggest you using the book functionality of Wikipedia to make it more readable/printable. I did the same for the C++0x page.