CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: A 'customised' std::list ??

    Over on the Microsoft forum one of the contributers suggested adding an extra line which - by some strange magic - seems to fix the compile:-

    Code:
    #include <list>
    
    using LT = std::list<int>;
    
    using func_void_t = void(LT::*)();
    using func_ref_t = LT::reference(LT::*)();
    using func_iter_t = LT::iterator(LT::*)();
    
    using unused = decltype(std::declval<LT>().unique()); // <--- New line
    
    int main (int argc, char *argv[])
    {
    // Non-overloaded members
       [...]
    
    // Members with overloads
       [...]
      func_void_t f5 = &LT::unique; // Now succeeds !!!
    
      return 0;
    }
    But even over there they reckon it's a compiler bug and needs to get reported to the VC development team.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #17
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: A 'customised' std::list ??

    The Bug has now been reported to the VS team and is now 'Under Investigation'. I'll update when there is more info.

    Nice workaround! I'd never of thought of that as that using unused... line should have absolutely no effect!
    Last edited by 2kaud; March 9th, 2021 at 05:05 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #18
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: A 'customised' std::list ??

    Did the VS team ever produce an explanation for this - or a fix?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  4. #19
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: A 'customised' std::list ??

    No. It's still marked as 'under investigation'. I guess they accept this as a bug, but that it's low on their priority list. When they'll get around to issuing a fix is really anyone's guess....
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #20
    Join Date
    Jun 2021
    Posts
    10

    Re: A 'customised' std::list ??

    Since the list contains pointers, rather than objects, you'll have to provide a custom comparator to compare the objects they point to. And since you're using a list, you have to use its own sort method: the generic std::sort algorithm only works on random-access sequences.

    EventList.sort([](Event * lhs, Event * rhs) {return lhs->time < rhs->time;});
    or, if you're stuck in the past and can't use lambdas:

    struct CompareEventTime {
    bool operator()(Event * lhs, Event * rhs) {return lhs->time < rhs->time;}
    };

    EventList.sort(CompareEventTime());
    If the list contained objects (as it probably should), then it might make sense to provide a comparison operator instead:

    bool operator<(Event const & lhs, Event const & rhs) {return lhs.time < rhs.time;}

    std::list<Event> EventList;
    //...
    EventList.sort();
    Last edited by 2kaud; June 28th, 2021 at 08:36 AM. Reason: Removed advertising link

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured