void bisectional_find_test_strings(std::vector<std::string>& values, std::string value_to_find) {

        using std::vector;
        using std::string;
        using std::cout;
        using std::endl;
        using std::getchar;

        auto begin = values.begin();
        auto end = values.end();

        //works with iterator math
        auto found = bisectional_find<string_vector_iterator, string>(
            values, value_to_find,
            [](vector<string>& v) { return v.begin(); },
            [](vector<string>& v) { return v.end(); },
            [](const string& a, const string& b) { return a != "" && a == b; });

        if (found == end)
            cout << "did not find " << value_to_find;
        else
            cout << "found " << value_to_find << " at index " << (found - begin);

        cout << endl;

        getchar();
    }
    void bisectional_find_test_ints(std::vector<int>& values, int value_to_find) {

        using std::vector;
        using std::cout;
        using std::endl;
        using std::getchar;

        auto begin = values.begin();
        auto end = values.end();

        //works with iterator math
        auto found = bisectional_find<int_vector_iterator, int>(
            values, value_to_find,
            [](vector<int>& v) -> int_vector_iterator { return v.begin(); },
            [](vector<int>& v) -> int_vector_iterator { return v.end(); },
            [](const int& a, const int& b) { return a > 0 && a == b; });
        
        if (found == end)
            cout << "did not find " << value_to_find;
        else
            cout << "found " << value_to_find << " at index " << (found - begin);

        cout << endl;

        getchar();
    }
Example #3
0
void read_source(const string &source, char* cells)
{
    state_type state = CODE;

    char *ptr = cells;
    int depth;
	for (auto i = source.begin();
            i != source.end();
            (state == RBRACE) ? (--i) : (++i)) {

        switch (state) {
        case CODE:
		    switch (i[0]) {
		    case '>':
    			++ptr;
    			break;
    		case '<':
    			--ptr;
    			break;
    		case '+':
     			++*ptr;
    			break;
    		case '-':
    			--*ptr;
    			break;
    		case '.':
    			putchar(*ptr);
    			break;
    		case ',':
    			*ptr = getchar();
			    break;
    		case '[':
                if (*ptr == 0) {
                    depth = 1;
                    state = LBRACE;
                }
                break;
            case ']':
                if (*ptr != 0) {
                    depth = -1;
                    state = RBRACE;
                }
                break;
    		}
            break;

        case LBRACE:
            switch (i[0]) {
            case '[':
                ++depth;
                break;
            case ']':
                --depth;
                break;
            }
            if (depth == 0) {
                state = CODE;
            }
            break;

        case RBRACE:
            switch (i[0]) {
            case '[':
                ++depth;
                break;
            case ']':
                --depth;
                break;
            }
            if (depth == 0) {
                state = CODE;
            }
            break;
        }
        #ifdef DEBUG
            print_cells(i[0], cells, DEBUG_CELL_COUNT);
            print_pointer(cells, ptr);
        #endif
	}
}