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 8159885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:04:09+00:00 2026-06-06T18:04:09+00:00

BOOL utils::GetLogicDrivesByFreeSpace(LPTSTR pDrives) { TCHAR szBuff[257]; TCHAR chMaxDrive; DWORD dwLogicalDrives; ULARGE_INTEGER freeBytesAvaliable, maxFreeBytesAvaliable; ULARGE_INTEGER

  • 0
BOOL utils::GetLogicDrivesByFreeSpace(LPTSTR pDrives)
{
    TCHAR szBuff[257];
    TCHAR chMaxDrive;
    DWORD dwLogicalDrives;
    ULARGE_INTEGER freeBytesAvaliable, maxFreeBytesAvaliable;
    ULARGE_INTEGER totalNumberOfBytes;
    std::map< ULARGE_INTEGER, TCHAR > driveMap;

    maxFreeBytesAvaliable.QuadPart = 0;
    dwLogicalDrives = GetLogicalDrives();
    for (int nDrive = 0; nDrive < 32; ++nDrive) {
        if (dwLogicalDrives && (1 << nDrive)) {
            _stprintf(szBuff, TEXT("%c:\\"), TEXT('A') + nDrive);
            //如果是硬盘分区
            if (GetDriveType(szBuff) == DRIVE_FIXED) {
                GetDiskFreeSpaceEx(szBuff,
                    &freeBytesAvaliable, &totalNumberOfBytes, NULL);
                driveMap.insert( std::pair< ULARGE_INTEGER, TCHAR >(freeBytesAvaliable.QuadPart, TEXT('A') + nDrive));
            }
        }
    }
    std::sort( driveMap.begin(), driveMap.end(), [](std::pair< ULARGE_INTEGER, TCHAR > n1, std::pair< ULARGE_INTEGER, TCHAR > n2) -> bool { return (n1.first.QuadPart < n2.first.QuadPart); } );
    int i = 0;
    for (std::map< ULARGE_INTEGER, TCHAR >::const_iterator iter = driveMap.begin(); iter != driveMap.end(); ++iter, ++i) {
        pDrives[i] = iter->second;
    }
    return true;
}

This lambda expression [](std::pair< ULARGE_INTEGER, TCHAR > n1, std::pair< ULARGE_INTEGER, TCHAR > n2) -> bool { return (n1.first.QuadPart < n2.first.QuadPart); } could not compile, Why???

thanks.

===JUST AS A NOTE===

Create a class:

struct CompareLargeInteger {
    bool operator()(ULARGE_INTEGER n1, ULARGE_INTEGER n2) {
        return (n1.QuadPart > n2.QuadPart);
    }
};

Then declare the driveMap as

std::map< ULARGE_INTEGER, TCHAR, CompareLargeInteger > driveMap;

Then everything is OK.

Give a insight into the MS’s STL

template<class _RanIt,
    class _Diff> inline
    void _Sort(_RanIt _First, _RanIt _Last, _Diff _Ideal)
    {   // order [_First, _Last), using operator<
    _Diff _Count;
    for (; _ISORT_MAX < (_Count = _Last - _First) && 0 < _Ideal; )
        {   // divide and conquer by quicksort
        _STD pair<_RanIt, _RanIt> _Mid =
            _Unguarded_partition(_First, _Last);
        _Ideal /= 2, _Ideal += _Ideal / 2;  // allow 1.5 log2(N) divisions

        if (_Mid.first - _First < _Last - _Mid.second)
            {   // loop on second half
            _Sort(_First, _Mid.first, _Ideal);
            _First = _Mid.second;
            }
        else
            {   // loop on first half
            _Sort(_Mid.second, _Last, _Ideal);
            _Last = _Mid.first;
            }
        }

    if (_ISORT_MAX < _Count)
        {   // heap sort if too many divisions
        _STD make_heap(_First, _Last);
        _STD sort_heap(_First, _Last);
        }
    else if (1 < _Count)
        _Insertion_sort(_First, _Last); // small
    }

__Count = __Last - __First, the minus operator is only supported by random access opeartor.

  • 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-06-06T18:04:12+00:00Added an answer on June 6, 2026 at 6:04 pm

    std::sort requires random access iterators, but std::map iterators are bidirectional iterators.

    I think you should read more about std::map. It is implicitly sorted based on the key type and the optional predicate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

bool hasDuplicate = false; int[] a = new int[] {1, 2, 3, 4}; int[]
bool myBool = true; byte myByte; This conversion runs myByte = Convert.ToByte(myBool); This conversion
bool isValid = false; string username = someadmin; If( !String.IsNullOrEmpty(username) && !( username.IndexOf(admin) !=
bool operator()(Iterator it1, Iterator it2) const { return (*it1 < *it2); } Can someone
- (BOOL) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CocosNode* spHead = [self getChildByTag:tagHead]; CocosNode* spBody
bool is_something_ok(int param,SomeStruct* p) { bool is_ok = false; // check if is_ok if(is_ok)
-(BOOL) textFieldShouldReturn:(UITextField*) theTextField{ [theTextField resignFirstResponder]; return YES; } it is not working....
bool operator == (const MyString& left, const MyString& right) { if(left.value == right.value) return
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
on some of my aspx page I am checking session like this if (bool.Parse(Session[YourAssessment].ToString())

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.