Click here to Skip to main content
15,891,184 members
Articles / Programming Languages / C++

Enumerator Lists and Enumerated Arrays

Rate me:
Please Sign up or sign in to vote.
4.60/5 (9 votes)
4 Oct 2011CPOL11 min read 59.1K   464   15  
Establishing a strong binding between enumerations and arrays
// This file is part of the lobster library
// Copyright: Andreas Raczek
// This file is published under the The Code Project Open License (CPOL) 
// See the file "CPOL.html" for the full license governing this code. 
#pragma once

namespace lobster {

namespace static_list {


template<typename list_in> struct sort_ascending;

template<
    typename parent, // may be list_item<...> or list_tail<...>
    typename parent::value_type value_first,
    typename parent::value_type value_last
> struct sort_ascending<
    list_item<parent, value_first, value_last>
> {
private:
    typedef typename sort_ascending<parent>::type sorted_parent;
    
    static const int p = find_insert_pos<
            sorted_parent,
            value_first,
            value_last
        >::value;

public:
    typedef typename list_insert_at<
            sorted_parent,
            p,
            value_first,
            value_last
        >::type type;
};


template<
    typename value_type
> struct sort_ascending<
    list_tail<value_type>
> {
    typedef list_tail<value_type> type;
};


}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions