简体   繁体   中英

C++: Why is std::greater<T>() included in iostream?

I noticed that my C++ code containing std::greater<T>() compiled well without including <functional> . This got me thinking. It turns out that this code compiles:

#include <iostream>
int main(){
    std::greater<T>();
}

But this one doesn´t:

int main(){           //<iostream> doesn´t get included
    std::greater<T>();
}

By which I could infer that <iostream> contains std::greater which seems somewhat odd to me. Can someone explain, why std::greater<T>() gets included with <iostream> ?

I´m using g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0 with C++14 if this matters.

it's not guaranteed by ISO standard. The implementation of that header uses it. You also may find that <utility> , <string> (may be included as part of <ios> or <iosfwd> ), <memory> and some <type_traits> may be available from <iostream> .

The five guaranteed headers are (since C++11): ios, iosfwd, istream, ostream, streambuf.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM