Q:

Xcode cannot find 'std' namespace

I have the following code
#ifndef TPSO1_thread_h
#define TPSO1_thread_h

#define _XOPEN_SOURCE

#include <ucontext.h>

struct Thread_Greater;

class Thread {
    ...

    friend struct Thread_Greater;
    friend class Scheduler;
};

struct Thread_Greater : public std::binary_function <Thread,Thread,bool> {
    ...
};

#endif

in a .h file. Problem is, when I try to compile it in xcode it says
#Error: use of undeclared identifier 'std'

In the line 
struct Thread_Greater : public std::binary_function <Thread,Thread,bool> {

Is there any include that I am missing?

A:

You need to include the headers for the library components you use. In this case std::binary_function is in <functional>, so you need this line in your code:
#include <functional>

Just to explain a bit more, the std namespace is not built-in to the C++ language (mostly). Unless it's actually declared somewhere in a program then it does not exist as far as the compiler is concerned.
It's even possible to build useful C++ programs that make no use of the standard library. The C++ specification includes a mode that may not even include a standard library: freestanding mode.
If you use something from the std namespace without that namespace having been declared in the program then you'll get an error telling you std hasn't been declared.
int main() {
  std::cout << "Hello\n";
}

main.cpp:2:3: error: use of undeclared identifier 'std'
  std::cout << "Hello\n";
  ^

If you use something and std has been declared, but not the specific member of std you're using, then you'll get an error about std not containing the thing you're using:
#include <utility> // declares std, but not std::cout

int main() {
  std::cout << "Hello\n";
}

main.cpp:4:12: error: no member named 'cout' in namespace 'std'
  std::cout << "Hello\n";
  ~~~~~^

