C++ error: no member named 'boyer_moore_searcher' in namespace 'std' - FreeBSD 12.3 and 12.4

Hi - I am trying to compile this example I found online. I am able to do this Windows VS 2019 and Debian g++ 8.3 as long as I specify c++17.

Using clang version 10.0.1
Code:
[jon2allen@freebsd12_3 ~/github/c++]$ cat string_search1.cpp
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <string>
#include <string_view>

int main()
{
    constexpr std::string_view haystack =
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
        "do eiusmod tempor incididunt ut labore et dolore magna aliqua";

    const std::string_view needle{"pisci"};

    if (const auto it = std::search(haystack.begin(), haystack.end(),
            std::boyer_moore_searcher(needle.begin(), needle.end()));
        it != haystack.end()
    )
        std::cout << "The string " << std::quoted(needle) << " found at offset "
                  << it - haystack.begin() << '\n';
    else
        std::cout << "The string " << std::quoted(needle) << " not found\n";
}
[jon2allen@freebsd12_3 ~/github/c++]$ c++ -std=c++17 string_search1.cpp -o string_search1
string_search1.cpp:17:18: error: no member named 'boyer_moore_searcher' in namespace 'std'
            std::boyer_moore_searcher(needle.begin(), needle.end()));
            ~~~~~^
1 error generated.
You have new mail in /var/mail/jon2allen
[jon2allen@freebsd12_3 ~/github/c++]$ c++ -std=c++20 string_search1.cpp -o string_search1
string_search1.cpp:17:18: error: no member named 'boyer_moore_searcher' in namespace 'std'
            std::boyer_moore_searcher(needle.begin(), needle.end()));
            ~~~~~^
1 error generated.
[jon2allen@freebsd12_3 ~/github/c++]$


[jon2allen@freebsd12_3 ~/github/c++]$ c++ --version
FreeBSD clang version 10.0.1 ([email]git@github.com[/email]:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611aa2)
Target: x86_64-unknown-freebsd12.3
Thread model: posix
InstalledDir: /usr/bin
 
std::boyer_moore_searcher requires libc++15, to be shipped in FreeBSD 13.3 or 14.0. Either switch to std::experimental::boyer_moore_searcher, bundle newer libc++ or use libstdc++ via GCC. Prefer experimental workaround as mixing different C++ libraries can cause crashes e.g., when a project depends on packages linked against system libc++.

C++:
#ifdef __cpp_lib_boyer_moore_searcher
#include <functional>
#else
#include <experimental/functional>
namespace std {
    using experimental::boyer_moore_searcher;
}
#endif
 
Yes, this works. I also found this searching that was a big clue.

rewrote it as below and now works.

C++:
//#include <algorithm>
//#include <functional>
#include <experimental/algorithm>
#include <experimental/functional>
#include <iomanip>
#include <iostream>
#include <string>
#include <string_view>

int main()
{
    constexpr std::string_view haystack =
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
        "do eiusmod tempor incididunt ut labore et dolore magna aliqua";

    const std::string_view needle{"pisci"};

    if (const auto it = std::experimental::search(haystack.begin(), haystack.end(),
            std::experimental::boyer_moore_searcher(needle.begin(), needle.end()));
        it != haystack.end()
    )
        std::cout << "The string " << std::quoted(needle) << " found at offset "
                  << it - haystack.begin() << '\n';
    else
        std::cout << "The string " << std::quoted(needle) << " not found\n";
}
 
Back
Top