Boost logo

Boost :

From: Vladislav Lazarenko (snail_at_[hidden])
Date: 2006-04-08 05:18:27


Pavel Vozenilek wrote:
>
> While this and similar tricks are forbidden by Standard
> almost all current compilers are so "buggy"
> to support the feature. Comeau has even special switch
> to enable the feature.
>
> See article
> http://www.cuj.com/documents/s=8943/cujexp0312wilson2/
> from Mathew Wilson for overview of these techniques.
>
> Generally, if something useful can be done
> because of widely present "bug" it is worth to consider.
> Boost.Typeof uses VC6 bug to implement
> otherwise impossible typeof there.
>
> /Pavel
>

AFAIK any tricks with typedefs are not legal in that context too. However, I am
looking forward to solution that just works with all compilers boost support and
the described technique will help us to support compilers that does not yet has
so beautiful bug as template friends. I will prepare the version of "sealed"
library taking that technique into account ASAP and we will take a look.

As for standard solution, I found one, but it is not looking good, see below.
Thank you for your interest.

-- Vladislav Lazarenko

//
// Copyright (c) 2006 Vladislav Lazarenko <snail_at_[hidden]>
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef BOOST_SEALED_HPP
#define BOOST_SEALED_HPP

// MS compatible compilers support #pragma once.
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

#define BOOST_DECLARE_SEALED(x) \
   class boost_sealed_impl_##x { \
     friend class x; \
   private: \
     boost_sealed_impl_##x() {} \
     ~boost_sealed_impl_##x() {} \
   }; \

#define BOOST_IMPLEMENT_SEALED(x) \
   virtual private boost_sealed_impl_##x

// Usage example:
//
// BOOST_DECLARE_SEALED(UniquePerson)
//
// class UniquePerson : BOOST_IMPLEMENT_SEALED(UniquePerson)
// {
// public:
// UniquePerson() {}
// ~UniquePerson() {}
// };
//

#endif


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk