Repository: pytorch
Issue: Deprecation warnings generated when including header files in C++17 code
Labels: triaged,module: build warnings,Stale

When including PyTorch header files in a C++ project that supports the C++17 standard a number of deprecation warnings are seen, for example:

```
C:\usr\local\include\pytorch\ATen/core/List.h(106,40): warning C4996: 'std::iterator<std::random_access_iterator_tag,T,ptrdiff_t,T *,T &>': warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. (The <iterator> header is NOT deprecated.) The C++ Standard has never required user-defined iterators to derive from std::iterator. To fix this warning, stop deriving from std::iterator and start providing publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators. You can define _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
C:\usr\local\include\pytorch\ATen/core/List.h(156,3): warning C4996: 'std::iterator<std::random_access_iterator_tag,T,ptrdiff_t,T *,T &>::difference_type': warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. (The <iterator> header is NOT deprecated.) The C++ Standard has never required user-defined iterators to derive from std::iterator. To fix this warning, stop deriving from std::iterator and start providing publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators. You can define _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
C:\usr\local\include\pytorch\c10/util/Optional.h(1129,3): warning C4996: 'std::_Conditionally_enabled_hash<_Kty,true>::result_type': warning STL4007: Many result_type typedefs and all argument_type, first_argument_type, and second_argument_type typedefs are deprecated in C++17. You can define _SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
C:\usr\local\include\pytorch\c10/util/TypeList.h(502,26): warning C4996: 'std::result_of_t': warning STL4014: std::result_of and std::result_of_t are deprecated in C++17. They are superseded by std::invoke_result and std::invoke_result_t. You can define _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
C:\usr\local\include\pytorch\c10/util/irange.h(19,32): warning C4996: 'std::iterator<std::input_iterator_tag,I,ptrdiff_t,I *,I &>': warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. (The <iterator> header is NOT deprecated.) The C++ Standard has never required user-defined iterators to derive from std::iterator. To fix this warning, stop deriving from std::iterator and start providing publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators. You can define _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
```

It is acknowledged that at the moment PyTorch itself builds with C++14 support so such errors won't be seen when building it. The issue arises when including PyTorch headers in builds supporting C++17 (and above) so it would be great if some or all of these deprecation warnings could be addressed.

Operating system version: Windows Server 2016
Compiler version: VS 2019 -  19.29.30136 for x64