C++ program compiling without functional header - c++

As per CPP Doc, std::greater is defined in <functional> header but my C++ program using std::greater is compiling with TDM-GCC-64 5.1.0 and running with only the following includes :
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
It could be because <algorithm> automatically includes <functional> but since this is not mentioned in the doc, I was wondering is there a way to know this before hand ?

Just to close the topic, the conclusion is that this is implementation dependent and all the necessary headers should be included for portability.

Related

Where is '__find_end' present in Visual Studio 19 C/C++ Development Tools?

I was trying to compile an old code, and received the following error:
error G1A4676F8: no member named '__find_end' in namespace 'std'
I searched online and found it is defined in stl_algo.h, which I couldn't find in my Windows system. Also, the documentations were of libstdc++4 and earlier.
The code compiles fine on https://godbolt.org/ with all MSVC versions.
The include statements are:
#include <string>
#include <algorithm>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <stdexcept>
The compiler shows an alternative as find_end defined in algorithm but I am not sure if __find_end has the same functionality as find_end.
So, my question is, is __find_end deprecated?
If not, where can I find it's declaration in Windows?
If yes, what are my alternatives? Is find_end a perfect substitute for __find_end?

Linux: Conflicts using inotify with fcntl

I'm having a strange linking issue after I included inotify in my program to monitor changes to a filesystem. The project includes <fcntl.h> in many other source files. However, when I include <sys/inotify.h> in the source file which is doing the directory monitoring, I get this error:
/usr/include/fcntl.h:30:1: error: expected initializer before ‘extern’
__BEGIN_DECLS
My project uses CMake, although that doesn't seem to be relevant for finding inotify. It IS finding the inotify declarations to my knowledge, since when I included , it threw an error that inotify_init() and the other functions I used were not defined. Inotify includes fcntl and is partially built on top of some of the functionality there, so my first thought was that it's importing a different version of fcntl than the rest of my program.
In ObjectManager.h:
#ifndef MANAGE_OBJECT_H
#define MANAGE_OBJECT_H
#include "config.h"
//includes all lua headers under extern 'C'
#include <lua.hpp>
#include <list>
#include <unordered_map>
#include <pthread.h>
class ObjectManager //...
The only thing that changed was ObjectManager.cc, with the addition of sys/notify and the implementation of the watcher (not included because this is a linking issue):
#include "config.h"
#include "ObjectManager.h"
#include "Control.h"
#ifdef OBJECT_MANAGER_ENABLED
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#include <unistd.h>
#include <fstream>
#include <sys/inotify.h>
//... inotify implementation
Where Control.h declares #include <fcntl.h>.
This is the closest issue I found, related to some problems in the implementation of different fcntl headers for userspace usage. https://lkml.org/lkml/2008/9/16/98
The same problem occurs on Linux 2.6 running on Centos 6 and Linux 4.0 running on Centos 7.
Any ideas on what is causing this error and how to successfully include inotify?
Resolution: A function definition lacked a semicolon at the END of ObjectManager.h right before a #endif, and the resulting GCC error that propagated through the next includes in a complicated manner, resulting in a strange preprocessor error in fcntl.h.

Xcode 7.1 and C++

I have a C++11 header and source file to call from swift (of course i'm including the header in the bridging header). I've set the build settings for C++ to:
"C++ Language Dialect" -> "C++11 [-std=c++11]"
"C++ Standard Library" -> "libc++ (LLVM standard C++ library with C++11 support)"
It still can't find some #include (file not found):
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include <utility>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <utility>
As mentioned in one of the comments, you can use a wrapper. In fact, the wrapper doesn't even have to be in Objective-C. It can actually be a C++ wrapper, but the functions intended to be called from Swift should have C linkage. See http://www.swiftprogrammer.info/swift_call_cpp.html for a tutorial.

Where is strtof() in VS2012?

I can litterally not find which library/header this function is in, I've looked at so many examples of people using this function, but there are no results...
These are all the stuff I've included:
#include "Console.h"
#include "Direct3D9.h"
#include <string>
#include <cerrno>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
But still strtof comes up as "Error namespace "std" has no member "strtof""
What I'm trying to do:
flValue = std::strtof( vszArgs.at( 1 ).c_str( ), NULL );
pConVar->Set( flValue );
Visual Studio 2012 does not implement strtof.
Link to MSDN bug report which includes a suggested workaround.
You can find it in cstdlib when using C++11. The information can easily be found here : http://www.cplusplus.com/reference/cstdlib/strtof/?kw=strtof
My guess is that you aren't compiling using c++11.
1) Include stdlib.h
#include <stdlib.h> /* strtof */
from http://www.cplusplus.com/reference/cstdlib/strtof/
If that still doesn't work...
2) Make sure your compiler is C++11 or newer
It's new as of C++11 so if you have an older compiler it won't work.
If that still doesn't work...
3) Your compiler may just not support it
Visual C++ 2012 does not have full support for the C++11 standard. See the Visual Studio bug "Missing strtof, strtold, strtoll, strtoull functions from stdlib.h".
We don't yet have those functions in the CRT. We will consider adding them to a future version of Visual C++.

build error with c++ - ‘find_if’ is not a member of ‘std'

While building a project, I get this cryptic error:
‘find_if’ is not a member of ‘std'
find_if() is used this way: std::find_if(...).
Any idea where it could come from ?
add the inclusion:
#include <algorithm>
to your implementation file.
Did you include the header
#include <algorithm>
You need #include <algorithm>
Include the <algorithm> header file:
#include <algorithm>