std::binary_function is missing in MSVC 14.37.32822

tashman 40 Reputation points
2023-08-18T19:13:44.3933333+00:00

The std::binary_function was not supposed to be removed until C++17, but it appears to have been removed in MSVC 14.37.32822. This seems to be due to the xstddef file was removed in this version, but the file exists in earlier versions like 14.36 and 14.34.

This is ultimately causing our code to fail to build with the following error:

Error C2039 'binary_function': is not a member of 'std'

Note that our project is being compiled with the "Default (ISO C++14 Standard)" so we haven't yet updated to C++17.

Is it expected for the std::binary_function to be removed in 14.37.32822 or is this a bug in MSVC?

For reference, here are exact locations of where the xstddef file is supposed to be:

C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.34.31933\include -> File exists (code builds fine)

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\include -> File does not exist (code fails to build)

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,664 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,550 questions
{count} votes

Accepted answer
  1. Minxin Yu 10,276 Reputation points Microsoft Vendor
    2023-08-21T02:28:29.2666667+00:00

    Hi,@tashman

    std::binary_function is in header file functional.
    You could test the sample below.
    I am using Version: VS2022 Preview. C++ 14. MSVC: 14.38.32919.

    #include <algorithm>
    #include <functional>
    #include <iostream>
    #include <vector>
    
    struct same : std::binary_function<int, int, bool>
    {
        bool operator()(int a, int b) const { return a == b; }
    };
    
    int main()
    {
        std::vector<char> v1{ 'A', 'B', 'C', 'D', 'E' };
        std::vector<char> v2{ 'E', 'D', 'C', 'B', 'A' };
        std::vector<bool> v3(v1.size());
    
        std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), std::not2(same()));
    
        std::cout << std::boolalpha;
        for (std::size_t i = 0; i < v1.size(); ++i)
            std::cout << v1[i] << " != " << v2[i] << " : " << v3[i] << '\n';
    }
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful