Does <algorithm> <cmath> include?

The following program compiles correctly:

#include <algorithm>

int main(int argc, char *argv[]) {

    return int(log(23.f));

}

(under g ++ 4.9.2 with flag -std=c++11)

The code uses a function logthat is defined on <cmath>. However, it does not include a heading <cmath>, but only a heading <algorithm>. Why g++doesn't it give any warnings and compiles code correctly?

+4
source share
3 answers

In the C ++ 11 standard, [res.on.headers] / 1 states that

++ ++. ++ , . ++ , , ++, , .

[algorithmms.general]/2:

<algorithm>

#include <initializer_list>

namespace std {
  // ......

<cmath> <initializer_list>. , . " " - , , .
, , <iostream> <ostream>, ++ 11.

+6

. <cinttypes> <cstdint>. . . <algorithm>, , (. ). , : <algorithm> <cmath>, . ++.

+9

:

g++ ?

++ , , #include. , , .


. "" , , , , .

, , lib++ ; export * , " , , ". std.algorithm, std.cmath, , , std.algorithm, std.cmath.

, " " , -fmodules .


clang- lib++ , , clang , :

main.cpp: 5: 16: : "log" "Darwin.C.math"

return int(log(23.f));
           ^  

/usr/include/math.h:387:15: note:

extern double log(double);  
              ^  

1 .

lib++ <algorithm> <cmath>, <random>. , , , .

+2
source

All Articles