Is there a way to manually expand variadic templates? - c++

Visual Studio does not currently support Variadic Templates and the official word is that VS2012 still will not support them.
I've ported my open source project to use C++11 and Variadic Templates are a huge part of that port. This means I can support clang++ 3.1 and g++ 4.5 but not Visual Studio.
So, my question is, does there exist a tool which will let me manually expand my variadic templates (to some N arguments) and check those into source control so that I can have stop-gap support for VisualStudio?

I recently wrote a tool to do exactly this (with the new VStudio 2012 C++ compiler not having support, I don't expect to get variadic templates for another year)
It's very basic, but I thought since there might be interest I might as well publish it.
You can download it from my website here: http://mlvdmeide.com/varexp

Related

How to automatically generate comments in Visual Studio 2017 and C++?

I'm wondering if there is a functionality in Visual Studio 2017 to automatically generate documentation comments for parameters, return value, etc. in C++.
In Eclipse, Java, I start typing /** above a method and the rest is generated.
As someone answered here this functionality exists for C#, but I can't find any hints for C++.
That's one of the things where C++ tooling really falls behind. For VS you will need to use some third party extension, such as CppTripleSlash or CppDoxyComplete. Both are kinda crappy though (no template support, no exception spec support, no attributes support, no SAL support, etc.).

Visual C++: Using nested templates, is it possible to mark ">>" instead of "> >" as error?

Is it possible to mark ">>" instead of "> >" as error in Visual Studio when using nested templates?
Example code:
void foo(std::vector<std::vector<double>>) {}
The Visual C++ compiler (I'm using VS10/2010) does not complain even on warning level 4, but building on Unix and Linux compilers fails with error (ideone):
error: '>>' should be '> >' within a nested template argument list
Is it possible to mark this as an error?
I want to make sure that my code is free of this trivial syntax errors before sending it to the CI server as much as possible...
C++11 made >> to end nested templates legal. The issue is that VC++ 2010 implements (and enables unconditionally) this part of C++11, but you're using other compilers which either don't implement this in the version you're targeting or you haven't enabled their C++11 mode.
VC++ doesn't support modes and instead simply enables bits and pieces of language specs as they get around to implementing them. So your solution is to either downgrade the VC++ compiler to a version that doesn't enable this feature, or upgrade or enable C++11 on the other compilers you're targeting so that this is not an error.
If you can't do either of those, and if you're not already using an automated build system then you can set one up to help catch these compatibilities errors faster than you currently are. Configure one so that as soon as any team member commits new code the code is checked on all the platforms you support.
Automated build systems often also allow users to provide code changes to be checked on all the build slaves directly from the team member's working directory, instead of requiring the code to be committed to the shared repo first. Setting this up is just about as good as having the initial development occur directly on each supported platform.
The reason this is an error using GCC 4.8.1 and not with Visual Studio 2010 (MSVC10) is that the former defaults to not using C++11 and the latter defaults to using it. Being able to use >> in a nested template list is a C++11 feature. To use C++11 features with GCC and Clang you need to pass in the -std=C++11 flag as a minimum to the compiler.
As for showing this within Visual Studio using intellisense I do not believe this is possible as it is not possible to tell MSVC to compile to different ISO standards.

C++11 on Windows

I'm wondering how well writing software in C++11 works on Windows yet. It would be most comfortable (and propably most natural) to use one of the native compilers for Windows - I'm thinking about Visual Studio 2012 Express or Visual Studio 2013 Express here. Everything I could find so far on that matter is
http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
(Comparison of C++11 features of VC10 and VC11, which seems to be quite bad)
http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx (not really transparent, didn't give me a good idea how well it works)
Does anyone have any experience how well the current Visual Studio versions can handle C++11? I really want to start using auto, lambdas, variadic templates, template aliases, initializer lists and rvalue references (to name just a few) and all the other good stuff right now, but if Windows might be a problem I might have to use C++03 further.
Another possibility seems to be to install LLVM and Clang on Windows. My primary platform is OSX, and on that system Clang's support for C++11 is really good. But I read that the LLVM-version of the standard library for C++ (libc++) does not work well on Windows. So LLVM/clang might not be an option.
What are your opinions on C++11 development on Windows?
Thank you!
I can only give you my experience as a developer, as I've been building against the cutting edge of C++ on Windows using Visual C++ for just about everything, while also installing several other compilers and IDEs (including building Clang myself on Windows for Visual Studio 2012, 2012 CTP, and 2013 Preview). The following is my experience up until right now (August 13th, 2013), and is based on Herb Sutter's talk and working with the compiler every day.
The Quick
Run in the opposite direction of Visual Studio / VC++. Support for C++11 is slow, and they're currently being crushed in terms of compiler features versus Clang and GCC.
The Present
Visual C++'s C++11 (and C++14 support) is beyond abysmal right now. They lack powerful features that make template metaprogramming in C++ great (using expressions in particular).
Using doesn't exist right now. I have spent hours and hours porting great C++11 code with using to VC++, only to have it break it certain places, snap, or just become near damn unmaintainable.
Variadic support in the CTP was horrifically terrible, and while it got better for Visual Studio 2013 Preview's version of the compiler, it's still fairly bad at complex variadic and template expressions that obey the standard (and compile fine in GCC and Clang).
=delete and =default are pretty much gone from VC++ right now; in the hopeful near future, maybe it will work out (and it should come "soon-ish", according to the roadmap) (I had to implement r-value constructors explicitly for many simple classes all the way down a 8-class inheritance hierarchy once. It was the worst slap in the face, when I watched GCC and Clang users get all of my explicit hardcoded work for free with =default).
As a holdover (primarily because of Windows OS code and some binary compatabilities), Empty-Base-Class-Optomizations in VC++ don't work. Don't expect your class hierarchy sizes or member layout to be optimized in the least (watch your ordering in std::tuple when packing variable types).
This is about all the frustrations I've come into contact with so far. They're work-aroundable -- I have to work with them every day -- but if you want great C++ support, you should jump for GCC or Clang and somehow make it work on your machine.
The Future
If you really want C++11, you will need to wait about a year, and even then Visual Studio 2013's release of VC++ will still be missing a few features (and don't expect them to be bugless either). VC++ for 2013 will also still be critically missing std::move and explicit r-value support in many places, making it painful when you expect things to work.
The Caveat
If you're not a powerful Vim user, you're low on options when it comes to IDEs that you can work with (that play nice with GDB/GCC or Clang).
QtCreator is nice, works with MinGW, and is generally fully featured enough to get work done.
Sublime Text can be used, but you'll have to write your own building system or delegate that to something else.
Code::Blocks's autocomplete is wonky and behaves strangely, and the IDE itself feels clunky.
Eclipse is supposed to be good, but my experiences with it are clunky and strange, with odd input lags at time (despite a 8.00 GB i7 Haswell machine using an SSD).
Visual Studio, as an IDE, is pretty solid. Then stack Visual Assist X on top, and it works pretty damn well for C++ coding. It's really the only reason I continue to stick with it, but I've already made headway into learning Vim so I can mostly ditch Visual Studio altogether, when the time comes.
About Libraries
Library support in VC++ is pretty complete (for as much as their broken compiler lets them be complete). It has regex, while most other libraries have non-existent or broken regex support. But that doesn't mean that the VC++ library plays nice with some C++11 features that it says it does (picture by melak47).
And Lastly
If you want code that you know is going to work in Windows, 100%, for the rest of eternity, you'll probably want to program against VC++. The other "benefit" is that the code you write in VC++ is the smallest subset of C++/C++11 you can write with, so in the end it should compile everywhere. Of course, that goes against the very idea of using beautiful C++11 and enjoying it, so... pick your poison(s) wisely.
VC's C++11 support is far from complete, but it does include the most important user-facing features.
And here's the other thing. In my experience, it is fine to install MinGW or Clang on Windows, but you're going to have some inconvenience because hardly anybody precompiles binaries for those compilers for Windows (whereas lots of people precompile binaries for Visual Studio).
In addition, there are as far as I am aware no environments for Windows which are remotely as advanced as Visual Studio for things like graphical debugging, intellisense, and stuff like that. When I tried Code::Blocks it just didn't work, realistically.
You can see here for a comprehensive comparison of compiler support for C++11 language features. Here's some info on VS's C++11/14 roadmap.
MSVC is lagging behind the other major C++ compilers but it's still got support for many of the most important features.
auto, lambdas, and rvalue references are available from VS10. IIRC there's a caveat with rvalue references that the compiler doesn't generate move construction and move assignment operators.
variadic templates and initializer lists are available in the VS2013 preview, including library support.
type aliasing (i.e., typedefs with the using keyword) is expected to be available in VS 2013 RTM.
If you don't need to interoperate with binaries generated by VS then installing another compiler such as GCC is workable. I understand Clang can also work in a mingw environment, with libstdc++ rather than libc++.
http://nuwen.net/mingw.html
The nuwen distro is AWESOME! It is MinGW but it comes out much quicker than MinGW as new GCC releases come out. It also comes with all of boost and other useful libraries already compiled. It is all I use on windows anymore.
We are using C++11 for a few months already in production software across windows and linux in some here.com products without any problems. We use auto, lambdas, range for... Using Visual studio 2012 and gcc 4.7.
I have been using VS2012 and used C++11 features where possible. There are some bugs in the implementations and I have found it helpful to have another compiler to hand when I get errors from Visual Studio to compare against.
Clang and GCC to lead the way in terms of C++11 feature support and it appears to be a neck-and-neck race in terms of C++11 support between the two. MSVC is sadly panting trying to keep up and lagging behind. The Nuwen MingGW distro is, as Jake mentions, excellent and appears to be working well with Eclipse (Kepler release) and I didn't encounter too much pain using it with Netbeans 7.4 either. The Nuwen distro is currently at version 11.2 at the time of writing and, as you can see at Stephan's website, is now x64-native, featuring GCC 4.8.1 and Boost 1.54.0, with GCC's default mode also set to C++11.
I'm certainly beginning to use Eclipse Kepler and Nuwen MinGW in preference to MSVC 2012 more and more, but I'm largely a hobbyist C++ programmer still getting my feet wet and may not have hit the more obscure problems that those to whom C++ is their bread and butter may know about.

visual c++ and C++ builder

Can C++builder compile any c++ source files.
I don't have a good knowledge in c++. but i have some experience in delphi.
I like to use c++ but confused which one to use
I know that cbuilder has vcl , easy to develop ,easy for delphi developer
But my problem is can it compile any c++ files (vc++ and other source files).
is it compatible with vc++ (excluding MFC and VCL). Can i use any APIs with c++builder
You'll find C++ Builder very comfy coming from Delphi if you don't care about MFC or .NET via C++/CLI etc and just want native C++ then either will work for you. Visual Studio 2010 supports a lot of the new C++0x features which is pretty nice, although they don't have variadic templates yet. I'm not sure how much of C++0x is in C++ Builder as yet but that could be worth looking into as a deciding factor.
It should be able to compile any standards conforming code. If the code uses extensions that another compiler provides, it will more than likely have problems. VC++ has quite a few extensions that are on by default and so someone using that compiler might use them with out realizing what is going on(the same applies to G++ the other major C++ compiler out there.)
In my experience, C++Builder's support for more advanced C++ code is limited. For example, many of Boost's libraries are unsupported in C++Builder, and I've often had to modify other open source libraries to get them to build properly in C++Builder (due to various bugs or limitations in C++Builder's compiler). Simpler C++ code can work without any problems.
So, depending on what C++ libraries / source files / APIs you're wanting to use, getting them to work in C++Builder may be very straightforward, or it may take significant work.
You can download a free version of C++ Builder at www.embarcadero.com. With that, you can test your libraries for compatibility.

How to find what's new in VC++ v10?

Googling nor binging "VC++ What's new C++0x" gives me nothing that tells me what is new.Is there an official page at msdn or something similiar that contains the information for VC++ 10? I've seen such for C#,there must be one for what I'd enjoy to read.
If not, please list the new features available in Visual Studio 2010 for VC++.
The Visual C++ Team Blog has frequent articles about what's new for VC++ in Studio 2010. It's not an exhaustive list, but does detail many of the new additions.
There's also an MS site which lists some of whats new.
Wikipedia's Visual C++ page has a recap, which I imagine will be updated frequently as we get closer to the release:
Visual C++ 2010 (known also as Visual
C++ 10.0) is planned for release on
April 12, 2010. It is currently in
development, and available publicly
only in the form of beta version, and
available on MSDN as a release
candidate. The Visual C++ team is
considering using a SQL Server Compact
database to store information about
the source code, including
IntelliSense information, for better
IntelliSense and code-completion
support. This version adds a
modern C++ parallel computing library
called the Parallel Patterns Library,
partial support for C++0x,
significantly improved IntelliSense,
and performance improvements to both
the compiler and generated code.
This version is built around .NET 4.0,
but supports compiling to machine
code. The partial C++0x support in
VC10 consists of 6 compiler features
(lambdas, rvalue references, auto,
decltype, static_assert, nullptr), and
some library features (e.g. moving the
TR1 components from std::tr1 namespace
directly to std namespace). Variadic
templates were also considered, but
delayed until some future version due
to lower priority which stemmed from
the fact that unlike other
costly-to-implement features in VC10
(lambda, rvalue references), this one
would benefit rather the minority of
library writers than the majority of
compiler end users.
Beta 2 version number: 16.00.21003.01 (this is the version of compiler; the IDE itself has version number 16.00.21006.01)
RC version number: 16.00.30128.01