you can use
Foo() : b(true ? std::make_shared<Bar>() : nullptr) {}
My suggestion is to push this logic to an auxiliary function.
class Foo {
private:
std::shared_ptr<Bar> b;
static std::shared_ptr<Bar> getB(bool flag)
{
return (flag ? std::make_shared<Bar>() : nullptr);
}
public:
Foo() : b(getB(true)) {}
};