This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Does there exist a static_warning?
Is there a way to implement non fatal messages at compile time just like static_assert do when its condition fail? Having a message that shows up always when the compiler encounters it is not enough, I want it to show up when, for example, a template is instantiated.
Would BOOST_STATIC_WARNING work for you?
Related
This question already has answers here:
Create a directory if it doesn't exist
(10 answers)
Closed 6 years ago.
I am looking to make a program using CreateDirectory(), RemoveDirectory(), and similar functions. One of the possible return errors from these commands ERROR_ALREADY_EXISTS. I want an if statement to catch this error and post a message on the screen and continue.
You need to call GetLastError () and check to see if the error condition meets ERROR_ALREADY_EXISTS; after calling CreateDirectory() and when it returns 0.
This question already has answers here:
Quick sort at compilation time using C++11 variadic templates
(2 answers)
Closed 7 years ago.
I wonder it it is possible to sort numbers during compilation? I mean something like that:
template<int...>
void sort(){
...
}
And:
sort<2,4,5,13,453>();
And I don't ask of solution or something like that. Please give me a hint or reference me.
Since C++ template system is known to be turing-complete, you can in principle compute everything that is computable at compile time. That includes sorting algorithms.
This question already has answers here:
What does "for(;;)" mean?
(5 answers)
Closed 7 years ago.
Simple question: I've been looking over boost's asio library, and keep coming across code like this.
for(;;){
//something
}
There's an example of this here.
Can anyone elaborate as to what using ";;" within a for loop does? I can't seem to understand it.
Its a simple infinite loop syntax, a complete code looks like this
for(<initialize>; <condition>; <increment/decrement>) {
<body>
}
Those I labelled with '< .. >' are optional.
This question already has answers here:
How will i know whether inline function is actually replaced at the place where it is called or not?
(10 answers)
Closed 8 years ago.
I am trying to diagnose a weird performance problem that I think is related to a failure of GCC to inline some function calls in C++, though I am not sure which function calls. Is there a flag to GCC to list all line numbers where inlining was performed?
The answer to your question is here:
C++: How will i know whether inline function is actually replaced?.
The question was slightly different from yours, but the responses are spot-on - and definitely enlightening. I encourage you to read them.
In answer to your question, however:-Winline will generate a warning if the compiler chooses not to inline:
https://gcc.gnu.org/onlinedocs/gcc-4.6.3/gcc/Warning-Options.html
This question already has answers here:
C++ equivalent of java's instanceof
(5 answers)
Closed 9 years ago.
How can I check the class type in c++?
In Java I used instanceof.
I prefer not to use dynamic cast, but only classic c++.
Is there any way?
Clarification:
It isn't a duplicate of another question in StackOverflow, since I asked how can I find it without using of dynamic_cast. In the other question, the answer was to use it. Please don't mark it as a duplicated.
There is no way to check class type without RTTI or it's home brew substitution. If application compiled without RTTI information about type is not stored anywhere.