⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 concepts.hpp

📁 boost库提供标准的C++ API 配合dev c++使用,功能更加强大
💻 HPP
📖 第 1 页 / 共 5 页
字号:
    template<>
    std::complex<float>
    ZeroElement (std::complex<float>) {
        return std::complex<float> (0.f);
    }
    template<>
    std::complex<double>
    ZeroElement (std::complex<double>) {
        return std::complex<double> (0.);
    }
#endif
    template<>
    vector<float> 
    ZeroElement (vector<float>) {
        return zero_vector<float> ();
    }
    template<>
    vector<double> 
    ZeroElement (vector<double>) {
        return zero_vector<double> ();
    }
#ifndef BOOST_MSVC
    template<>
    vector<std::complex<float> > 
    ZeroElement (vector<std::complex<float> >) {
        return zero_vector<std::complex<float> > ();
    }
    template<>
    vector<std::complex<double> > 
    ZeroElement (vector<std::complex<double> >) {
        return zero_vector<std::complex<double> > ();
    }
#endif
    template<>
    matrix<float> 
    ZeroElement (matrix<float>) {
        return zero_matrix<float> ();
    }
    template<>
    matrix<double> 
    ZeroElement (matrix<double>) {
        return zero_matrix<double> ();
    }
#ifndef BOOST_MSVC
    template<>
    matrix<std::complex<float> > 
    ZeroElement (matrix<std::complex<float> >) {
        return zero_matrix<std::complex<float> > ();
    }
    template<>
    matrix<std::complex<double> > 
    ZeroElement (matrix<std::complex<double> >) {
        return zero_matrix<std::complex<double> > ();
    }
#endif

    template<class T>
    T 
    OneElement (T);
    template<>
    float
    OneElement (float) {
        return 1.f;
    }
    template<>
    double 
    OneElement (double) {
        return 1.;
    }
#ifndef BOOST_MSVC
    template<>
    std::complex<float>
    OneElement (std::complex<float>) {
        return std::complex<float> (1.f);
    }
    template<>
    std::complex<double>
    OneElement (std::complex<double>) {
        return std::complex<double> (1.);
    }
#endif
    template<>
    matrix<float> 
    OneElement (matrix<float>) {
        return identity_matrix<float> ();
    }
    template<>
    matrix<double> 
    OneElement (matrix<double>) {
        return identity_matrix<double> ();
    }
#ifndef BOOST_MSVC
    template<>
    matrix<std::complex<float> > 
    OneElement (matrix<std::complex<float> >) {
        return identity_matrix<std::complex<float> > ();
    }
    template<>
    matrix<std::complex<double> > 
    OneElement (matrix<std::complex<double> >) {
        return identity_matrix<std::complex<double> > ();
    }
#endif

    template<class E1, class E2>
    bool 
    operator == (const vector_expression<E1> &e1, const vector_expression<E2> &e2) {
        typedef BOOST_UBLAS_TYPENAME promote_traits<BOOST_UBLAS_TYPENAME E1::value_type, 
                                                    BOOST_UBLAS_TYPENAME E2::value_type>::promote_type value_type;
        typedef BOOST_UBLAS_TYPENAME type_traits<value_type>::real_type real_type;
        return norm_inf (e1 - e2) == real_type ();
    }
    template<class E1, class E2>
    bool
    operator == (const matrix_expression<E1> &e1, const matrix_expression<E2> &e2) {
        typedef BOOST_UBLAS_TYPENAME promote_traits<BOOST_UBLAS_TYPENAME E1::value_type,
                                                    BOOST_UBLAS_TYPENAME E2::value_type>::promote_type value_type;
        typedef BOOST_UBLAS_TYPENAME type_traits<value_type>::real_type real_type;
        return norm_inf (e1 - e2) == real_type ();
    }

    template<class T>
    struct AdditiveAbelianGroupConcept {
        typedef T value_type;

        static void constraints () {
            bool r;
            value_type a = value_type (), b = value_type (), c = value_type ();
            r = (a + b) + c == a + (b + c);
            r = ZeroElement (value_type ()) + a == a;
            r = a + ZeroElement (value_type ()) == a;
            r = a + (- a) == ZeroElement (value_type ());
            r = (- a) + a == ZeroElement (value_type ());
            r = a + b == b + a;
            ignore_unused_variable_warning (r);
        }
    };

    template<class T>
    struct MultiplicativeAbelianGroupConcept {
        typedef T value_type;

        static void constraints () {
            bool r;
            value_type a = value_type (), b = value_type (), c = value_type ();
            r = (a * b) * c == a * (b * c);
            r = OneElement (value_type ()) * a == a;
            r = a * OneElement (value_type ()) == a;
            r = a * (OneElement (value_type ()) / a) == a;
            r = (OneElement (value_type ()) / a) * a == a;
            r = a * b == b * a;
            ignore_unused_variable_warning (r);
        }
    };

    template<class T>
    struct RingWithIdentityConcept {
        typedef T value_type;

        static void constraints () {
            AdditiveAbelianGroupConcept<value_type>::constraints ();
            bool r;
            value_type a = value_type (), b = value_type (), c = value_type ();
            r = (a * b) * c == a * (b * c);
            r = (a + b) * c == a * c + b * c;
            r = OneElement (value_type ()) * a == a;
            r = a * OneElement (value_type ()) == a;
            ignore_unused_variable_warning (r);
        }
        static void constraints (int) {
            AdditiveAbelianGroupConcept<value_type>::constraints ();
            bool r;
            value_type a = value_type (), b = value_type (), c = value_type ();
            r = prod (T (prod (a, b)), c) == prod (a, T (prod (b, c)));
            r = prod (a + b, c) == prod (a, c) + prod (b, c);
            r = prod (OneElement (value_type ()), a) == a;
            r = prod (a, OneElement (value_type ())) == a;
            ignore_unused_variable_warning (r);
        }
    };

    template<class T>
    struct CommutativeRingWithIdentityConcept {
        typedef T value_type;

        static void constraints () {
            RingWithIdentityConcept<value_type>::constraints ();
            bool r;
            value_type a = value_type (), b = value_type ();
            r = a * b == b * a;
            ignore_unused_variable_warning (r);
        }
    };

    template<class T>
    struct FieldConcept {
        typedef T value_type;

        static void constraints () {
            CommutativeRingWithIdentityConcept<value_type>::constraints ();
            bool r;
            value_type a = value_type ();
            r = a == ZeroElement (value_type ()) || a * (OneElement (value_type ()) / a) == a;
            r = a == ZeroElement (value_type ()) || (OneElement (value_type ()) / a) * a == a;
            ignore_unused_variable_warning (r);
        }
    };

    template<class T, class V>
    struct VectorSpaceConcept {
        typedef T value_type;
        typedef V vector_type;

        static void constraints () {
            FieldConcept<value_type>::constraints ();
            AdditiveAbelianGroupConcept<vector_type>::constraints ();
            bool r;
            value_type alpha = value_type (), beta = value_type ();
            vector_type a = vector_type (), b = vector_type ();
            r = alpha * (a + b) == alpha * a + alpha * b;
            r = (alpha + beta) * a == alpha * a + beta * a;
            r = (alpha * beta) * a == alpha * (beta * a);
            r = OneElement (value_type ()) * a == a;
            ignore_unused_variable_warning (r);
        }
    };

    template<class T, class V, class M>
    struct LinearOperatorConcept {
        typedef T value_type;
        typedef V vector_type;
        typedef M matrix_type;

        static void constraints () {
            VectorSpaceConcept<value_type, vector_type>::constraints ();
            bool r;
            value_type alpha = value_type (), beta = value_type ();
            vector_type a = vector_type (), b = vector_type ();
            matrix_type A = matrix_type ();
            r = prod (A, alpha * a + beta * b) == alpha * prod (A, a) + beta * prod (A, b);
            ignore_unused_variable_warning (r);
        }
    };
 
    void concept_checks () {

        // Storage
#if defined (INTERNAL) || defined (INTERNAL_STORAGE)
        StorageContainerConcept<const std::vector<double> >::constraints ();
        MutableStorageContainerConcept<std::vector<double> >::constraints ();
        RandomAccessIteratorConcept<std::vector<double>::const_iterator, std::ptrdiff_t, double>::constraints ();
        MutableRandomAccessIteratorConcept<std::vector<double>::iterator, std::ptrdiff_t, double>::constraints ();

        StorageContainerConcept<const bounded_array<double, 1> >::constraints ();
        MutableStorageContainerConcept<bounded_array<double, 1> >::constraints ();
        RandomAccessIteratorConcept<bounded_array<double, 1>::const_iterator, std::ptrdiff_t, double>::constraints ();
        MutableRandomAccessIteratorConcept<bounded_array<double, 1>::iterator, std::ptrdiff_t, double>::constraints ();

        StorageContainerConcept<const unbounded_array<double> >::constraints ();
        MutableStorageContainerConcept<unbounded_array<double> >::constraints ();
        RandomAccessIteratorConcept<unbounded_array<double>::const_iterator, std::ptrdiff_t, double>::constraints ();
        MutableRandomAccessIteratorConcept<unbounded_array<double>::iterator, std::ptrdiff_t, double>::constraints ();

        StorageContainerConcept<const array_adaptor<double> >::constraints ();
        MutableStorageContainerConcept<array_adaptor<double> >::constraints ();
        RandomAccessIteratorConcept<array_adaptor<double>::const_iterator, std::ptrdiff_t, double>::constraints ();
        MutableRandomAccessIteratorConcept<array_adaptor<double>::iterator, std::ptrdiff_t, double>::constraints ();

        IndexSetConcept<range>::constraints ();
        RandomAccessIteratorConcept<range::const_iterator, std::ptrdiff_t, std::size_t>::constraints ();

        IndexSetConcept<slice>::constraints ();
        RandomAccessIteratorConcept<slice::const_iterator, std::ptrdiff_t, std::size_t>::constraints ();

        IndexSetConcept<indirect_array<> >::constraints ();
        RandomAccessIteratorConcept<indirect_array<>::const_iterator, std::ptrdiff_t, std::size_t>::constraints ();
#endif

        // Sparse Storage
#if defined (INTERNAL) || defined (INTERNAL_STORAGE_SPARSE)
#ifndef BOOST_UBLAS_NON_STD
        SparseStorageContainerConcept<const std::map<std::size_t, double> >::constraints ();
        MutableSparseStorageContainerConcept<std::map<std::size_t, double> >::constraints ();
        BidirectionalIteratorConcept<std::map<std::size_t, double>::const_iterator, std::pair<std::size_t, double> >::constraints ();
        MutableBidirectionalIteratorConcept<std::map<std::size_t, double>::iterator, std::pair<std::size_t, double> >::constraints ();
#endif

        SparseStorageContainerConcept<const map_array<std::size_t, double> >::constraints ();
        MutableSparseStorageContainerConcept<map_array<std::size_t, double> >::constraints ();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -