user-defined-literals

Is it possible to disable GCC warning about missing underscore in user defined literal?

微笑、不失礼 提交于 2020-01-03 07:25:07
问题 void operator"" test( const char* str, size_t sz ) { std::cout<<str<<" world"; } int main() { "hello"test; return 0; } In GCC 4.7, this generates "warning: literal operator suffixes not preceded by '_' are reserved for future standardization [enabled by default]" I understand why this warning is generated, but GCC says "enabled by default". Is it possible to disable this warning without just disabling all warnings via the -w flag? 回答1: After reading several comments to this question, I

Overloading assignment operator for type deduction

為{幸葍}努か 提交于 2019-12-24 14:08:37
问题 Here's the ideone code: http://ideone.com/Qp8Eqg My question is, is it possible to force a conversion based on the lvalue alone? For example, [Seconds] s = 2_h + 60_s; cout <<s.getSeconds()<<endl; Obviously, I would have to write something like 2_h.toSeconds(), but that would be too verbose and doesn't achieve the idea. 回答1: To allow this (which is more likely your question than what you wrote, correct me if I'm wrong): Seconds s = 2_h; the following would work: Add operator Seconds() const

Overloading rules for User-defined-literals in c++0x

邮差的信 提交于 2019-12-24 00:32:52
问题 I am a little confused about overloading rules, let's say there are following literal operators, unsigned long long operator "" _xx(unsigned long long cooked_literal_int); //1 unsigned long long operator "" _xx(const char * raw_literal_string); // 2 unsigned long long operator "" _xx(long double cooked_literal_double); // 3 if both 1, 2, & 3 are defined, the overloading is obvious, 13_xx //call 1 13.5_xx //call 3 if 1 & 2 are defined, 13_xx //call 1 13.5_xx //call 2 if 2 & 3 are defined 13_xx

How do I define a negative UDL in c++11 (are they disallowed?)?

独自空忆成欢 提交于 2019-12-21 10:55:34
问题 I'm not even sure if negative User-Defined Literals are allowed. If not, why were they left out? For example, I would like to use: auto money_i_owe_jack = -52_jpy; This is what I tried using gcc 4.7.2: constexpr int64_t operator "" _jpy(long long l) { return static_cast<int64_t>(l); } ERROR Test_udl.cpp:60:47: error: ‘constexpr int64_t operator"" _jpy(long long int)’ has invalid argument list 回答1: Integer literals need to be accepted as unsigned long long . The negative sign is not part of

How to write an C/C++ application that writes to a /var/log/myapp directory?

[亡魂溺海] 提交于 2019-12-21 10:54:12
问题 Background On Linux systems, Application Logs exist in subdirectories of /var/log , which is owned by root/root and has 755 permissions on my system. For example, I see /var/log/mysql and /var/log/samba . Question If I want a myapp to be able to write into a /var/log/myapp , what is the canonical way of accomplishing this in C/C++? Thoughts Do I have to do something crazy like setuid root if I don't want to sudo a_setup_script.sh ? Note that I am aware of the syslog routines, but they are

Using a C++ user-defined literal to initialise an array

让人想犯罪 __ 提交于 2019-12-21 07:13:40
问题 I have a bunch of test vectors, presented in the form of hexadecimal strings: MSG: 6BC1BEE22E409F96E93D7E117393172A MAC: 070A16B46B4D4144F79BDD9DD04A287C MSG: 6BC1BEE22E409F96E93D7E117393172AAE2D8A57 MAC: 7D85449EA6EA19C823A7BF78837DFADE etc. I need to get these into a C++ program somehow, without too much editing required. There are various options: Edit the test vectors by hand into the form 0x6B,0xC1,0xBE,... Edit the test vectors by hand into the form "6BC1BEE22E409F96E93D7E117393172A"

Literal operator template: why not string?

不羁岁月 提交于 2019-12-21 04:40:29
问题 Once again, while replying to another question, I forgot (my fault) that literal operator templates are picked up from the set of declarations only when integer or floating literals are found. As an example: template <char... C> constexpr int operator "" _x() { return 0; } It can be used as 10_x , but it cannot be used neither as foo_x nor as "foo"_x. Apart for the obvious reason that is because the standard says that , what's the technical reason (if any) for which they are not considered

Fixed-width integer literals in C++?

假如想象 提交于 2019-12-20 18:36:22
问题 C++11 first introduced support for defining new literals into C++ by means of user-defined literals . Does C++11 or later also predefine suffixes for fixed-width integer literals for types in <cstdint> ? 回答1: No. As of C++14 the only literal suffixes defined by the standard are provided by <chrono> , <complex> and <string> headers in the standard library. The <chrono> header defines the h , min , s , ms , us , ns suffixes for time durations, <complex> defines the i , il and if suffixes for

Fixed-width integer literals in C++?

梦想的初衷 提交于 2019-12-20 18:36:03
问题 C++11 first introduced support for defining new literals into C++ by means of user-defined literals . Does C++11 or later also predefine suffixes for fixed-width integer literals for types in <cstdint> ? 回答1: No. As of C++14 the only literal suffixes defined by the standard are provided by <chrono> , <complex> and <string> headers in the standard library. The <chrono> header defines the h , min , s , ms , us , ns suffixes for time durations, <complex> defines the i , il and if suffixes for

Why doesn't std::string define multiplication or literals? [closed]

梦想与她 提交于 2019-12-20 06:25:37
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . In the language I was first introduced to, there was a function repeat() , that took a string, and repeated it n times. For example,