Program Listing for File containers.hpp

Return to documentation for file (/tmp/ws/src/ecl_core/ecl_concepts/include/ecl/concepts/containers.hpp)

/*****************************************************************************
** Ifdefs
*****************************************************************************/

#ifndef ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_
#define ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/

#include <ecl/config/ecl.hpp>
#include <ecl/type_traits/fundamental_types.hpp>
#include "macros.hpp"

/*****************************************************************************
** Namespaces
*****************************************************************************/

namespace ecl {

/*****************************************************************************
** Concept [Container]
*****************************************************************************/

template <typename Implementation>
class ContainerConcept {
public:

    ecl_compile_time_concept_test(ContainerConcept)
    {
        iter = container.begin();
        iter = container.end();
        unsigned int n;
        n = container.size();
                (void) n; // remove set but not used warnings.
    }

private:
    // Putting instantiations here actually saves instantiation (which can cause a
    // problem if there is no default constructor).
    Implementation container;
    typename Implementation::iterator iter;
};
template <typename Implementation>
class DynamicContainerConcept {
public:

    ecl_compile_time_concept_test(DynamicContainerConcept)
    {
        iter = container.begin();
        iter = container.end();
        unsigned int n;
        n = container.size();
        container.resize(1);
                (void) n; // remove set but not used warnings.
    }

private:
    // Putting instantiations here actually saves instantiation (which can cause a
    // problem if there is no default constructor).
    Implementation container;
    typename Implementation::iterator iter;
};

namespace concepts {

template <typename T, bool Result=false>
class SignedByteTest {
private:
    SignedByteTest() {}
};

template <typename T>
class SignedByteTest<T,true> {
public:
    SignedByteTest() {}
};

template <typename T, bool Result=false>
class UnsignedByteTest {
private:
    UnsignedByteTest() {}
};

template <typename T>
class UnsignedByteTest<T,true> {
public:
    UnsignedByteTest() {}
};

template <typename T>
class SignedByteTestCheck : public SignedByteTest<T, ecl::is_signed_byte<T>::value > {};

template <typename T>
class UnsignedByteTestCheck : public UnsignedByteTest<T, ecl::is_unsigned_byte<T>::value > {};

template <typename T>
class ByteTest {
private:
    ByteTest() {}
};

template <>
class ByteTest<unsigned char> {
public:
    ByteTest() {}
};
template <>
class ByteTest<char> {
public:
    ByteTest() {}
};

template <>
class ByteTest<signed char> {
public:
    ByteTest() {}
};

} // namespace concepts
template <typename Implementation>
class UnsignedByteContainerConcept {
public:

    ecl_compile_time_concept_test(UnsignedByteContainerConcept)
    {
        typedef typename Implementation::value_type element_type;
        iter = container.begin();
        iter = container.end();
        unsigned int n;
        n = container.size();
        // If not a char, this results in a private call -> compile time error!
        concepts::UnsignedByteTestCheck<element_type> char_test;
                (void) n; // remove set but unused warnings.
    }

private:
    // Putting instantiations here actually saves instantiation (which can cause a
    // problem if there is no default constructor).
    Implementation container;
    typename Implementation::iterator iter;
};

template <typename Implementation>
class SignedByteContainerConcept {
public:

    ecl_compile_time_concept_test(SignedByteContainerConcept)
    {
        typedef typename Implementation::value_type element_type;
        iter = container.begin();
        iter = container.end();
        unsigned int n;
        n = container.size();
        // If not a char, this results in a private call -> compile time error!
        concepts::SignedByteTestCheck<element_type> char_test;
    }

private:
    // Putting instantiations here actually saves instantiation (which can cause a
    // problem if there is no default constructor).
    Implementation container;
    typename Implementation::iterator iter;
};

template <typename Implementation>
class ByteContainerConcept {
public:

    ecl_compile_time_concept_test(ByteContainerConcept)
    {
        typedef typename Implementation::value_type element_type;
        iter = container.begin();
        iter = container.end();
        unsigned int n;
        n = container.size();
        // If not a char, this results in a private call -> compile time error!
        concepts::ByteTest<element_type> char_test;
                (void) n; // remove set but unused warnings.
    }

private:
    // Putting instantiations here actually saves instantiation (which can cause a
    // problem if there is no default constructor).
    Implementation container;
    typename Implementation::iterator iter;
};

} // namespace ecl

#endif /* ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_ */