Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:45:33+00:00 2026-05-25T15:45:33+00:00

boost::filesystem::recursive_directory_iterator end, begin(directory); auto num_of_files=std::count_if(begin, end, std::not1(boost::filesystem::is_directory))); I am trying to negate the function

  • 0
boost::filesystem::recursive_directory_iterator end, begin(directory);

auto num_of_files=std::count_if(begin, end, 
        std::not1(boost::filesystem::is_directory)));

I am trying to negate the function is_directory on the above directory iterator but am hitting a brick wall. I have tried specifying the template for not1 as bool(*)(const boost::filesystem::path&) and tried static casting the function both without success.

I know I can resort to a lamdba but this is cleaner if it works.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:45:33+00:00Added an answer on May 25, 2026 at 3:45 pm

    std::not1 needs a function object as its argument. This function object can be obtained with std::ptr_fun, so this should work:

    auto num_of_files=std::count_if(begin, end, 
            std::not1(std::ptr_fun((bool(*)(const boost::filesystem::path&))boost::filesystem::is_directory)));
    

    (the number of parentheses is probably incorrect). BTW, you need the cast because is_directory is an overloaded function.

    However, since you tag you question c++11, you could use lambdas:

    auto num_of_files=std::count_if(begin, end, [](const boost::filesystem::path& p) { return !boost::filesystem::is_directory(p); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

code: boost::filesystem::path config_folder(Config::CONFIG_FOLDER_NAME); if( !(boost::filesystem::exists(config_folder))) { std::cout << Network Config Directory not found...\n; std::cout
I want to use the recursive_directory_iterator offered by boost::filesystem to delete a directory. But
I'm trying to use boost::filesystem to copy files and folders (just like a standard
this code: boost::filesystem::is_directory(/usr/include); work fine. both this code: boost::filesystem::is_directory(L/usr/include); throw an exception: terminate called
I have the following code which i m trying to compile: #include <boost/filesystem/convenience.hpp> #include
When using Boost Filesystem's createdirectory (and createdirectories) function in the following example, / is
#include <boost/filesystem/path.hpp> #include <boost/filesystem/operations.hpp> using namespace std; using namespace boost; int main() { boost::filesystem::path
I keep running across errors when trying to compile code which utilizes the boost::filesystem
I am currently catching errors from boost::filesystem::is_directory and showing the error to the user
I'm using Boost.Filesystem to create a listing of files in a directory. I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.