27536

constexpr won't work using Visual C++ Compiler Nov 2013 CTP (CTP_Nov2013)

Question:

I'm trying to implement a compile-time hash algorithm using constexpr. I Downloaded Nov 2013 CTP because it has supported for constexpr but thats a lie...

#define hashCharacter(T, J) (((T >> 0x0D) | (T << 0x13)) + J) unsigned long constexpr GetHashCompile(const char * asSource, unsigned long asValue = 0) { return asSource[0] == '\0' ? asValue : GetHashCompile(asSource + 1, hashCharacter(asValue, asSource[0])); } int main(int a, char ** b) { const auto value = GetHashCompile("Hello from compiler"); printf("%d", value); }

GetHashCompile will not be generated at compile-time rather than runtime. How could i acomplish the above code using Visual Studio?. The same code works perfecly using GCC or CLANG.

Answer1:

Actually, the November 2013 CTP does not claim to fully support constexpr, but only claims to have a partial support for constexpr. The <a href="http://blogs.msdn.com/b/vcblog/archive/2013/12/02/c-11-14-core-language-features-in-vs-2013-and-the-nov-2013-ctp.aspx" rel="nofollow">features list</a> explicitely tells that constexpr is not supported for member functions and for arrays. Since string literals are a kind of array, they are not supported either:

<blockquote>

The CTP supports C++11 constexpr, except for member functions. (Another limitation is that arrays aren't supported.) Also, it doesn't support C++14's extended constexpr rules.

</blockquote>

Recommend

  • Netlify fails to deploy site after public is added to .gitignore
  • Why net().get on success return empty string
  • importing javaScript to Angular2
  • Android Swipe Images
  • How to calculate a point on a rotated axis?
  • Make ASP.NET web application FIPS Compliant?
  • Word to html conversion using php
  • How to import firefox cookies to python requests
  • ProgressDialog.show inside AsyncTask stop my Program from execution
  • Matplotlib: subplot
  • twitter bootstrap for high resolution mobile displays
  • I am trying to create an app in android to insert data into sql server through a web service.
  • LIBSODIUM decrypt data inside mysql query like did with AES_DECRYPT
  • What is the purpose of set clock skew in wcf security mode settings
  • Parsing string using the Scanner class
  • App crashes when switching to landscape layout
  • A library that can fill Java object with data declared in Excel file
  • Firebase suddenly reports invalid signature
  • Send HTML Mail with Unicode
  • Validating a Firebase Key [duplicate]
  • Jekyll - How do I create pages in the root directory?
  • Filtering out choiceless polls in the Django tutorial causes polls in the index to duplicate
  • android : speech recognition what are the technologies available
  • Boolean filter using a timestamp value on a dataframe in Python
  • css: column-count 3, image floating spanning 2, chrome not playing. why?
  • Autocomplete source from project settings
  • Java Collections.shuffle() weird behaviour [closed]
  • Ruby on Rails: Get mediaplayer information (iTunes, TRAKTOR, Cog; current song + playlist)
  • How to join two tables from different databases
  • Why is ordered choice in pyparsing failing for my use case?
  • Stacked bar chart with continuous time-axis as x-axis
  • Why isn't stemDocument stemming?
  • Google App Engine Datastore: Dealing with eventual consistency
  • Background transfer download task failed when app was closed
  • Excel VBA : conditional formatting of sheet1 cells from sheet2 values in excel 2007
  • How to use FirstOrDefault inside Include
  • PHP Permalinks.. how to change?
  • Running R's aov() mixed effects model from Python using rpy2
  • ReferenceError: TextEncoder is not defined