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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:25:49+00:00 2026-06-06T14:25:49+00:00

I came across this example class http://www.boost.org/doc/libs/1_49_0/libs/smart_ptr/sp_techniques.html#as_lock and I’m struggling with the syntax. class

  • 0

I came across this example class http://www.boost.org/doc/libs/1_49_0/libs/smart_ptr/sp_techniques.html#as_lock and I’m struggling with the syntax.

class shared_lock
{

private:

    shared_ptr<void> pv;

public:

    template<class Mutex> explicit shared_lock(Mutex & m): pv((m.lock(), &m), mem_fn(&Mutex::unlock)) {}
};

I (believe I) understand everything except this part “(m.lock(), &m)”. That entire thing appears to be the first parameter to initialize the smart pointer. What does that compound statement evaluate to? Is it simply the address of m? Why is the lock placed there as part of the parameter list (and how is it legal)? Instead, I would have expected a statement like:

template<class Mutex> explicit shared_lock(Mutex & m): pv(&m, mem_fn(&Mutex::unlock)) {m.lock();}

Does my alternate statement change the functionality?

  • 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-06T14:25:52+00:00Added an answer on June 6, 2026 at 2:25 pm

    What does that compound statement evaluate to? Is it simply the address of m?

    Yes

    Why is the lock placed there as part of the parameter list (and how is it legal)?

    The constructor needs to acquire the lock and it that’s a conveinent place to put it. otherwise the shared pointer would have to be set in the constructor’s body.

    It’s legal because expressions, including the comma operator, are used in initializers. The extra parentheses are needed to disambiguate the comma operator from the comma separating parameters, but otherwise most any expression is allowed.

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

Sidebar

Related Questions

I'm reading Effective C++ and came across this example: class Window { // base
I came across this example in Head First Design Patterns book. Pizza class has
I came across this example here : #include <vector> #include <cstddef> template<typename Tag> class
I came across this primer on coding HTML: http://css-tricks.com/examples/CleanCode/Beautiful-HTML.png . Among other things it
While I was reading Oracle Swing documentation, I came across this example of a
The other day, I came across this construct: static_cast<size_type>(-1) in some example C++ code,
Just came across this by Chris Coyier - http://css-tricks.com/examples/CSSTabs/ Can anyone explain me, how
After searching for a tableless model example I came across this code which seems
I've been reading up on class operators and came across the following example: class
I've just came across this example : Scroll down to the bottom of the

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.