Setting one key to 15 different numbers

Hi,
I have to create a program with a Bingo board that can cross out numbers as you read them in from a text file. The only difference between my project and the other projects I have mentioned is the way the board is set up. Instead of having only the BINGO columns, my board has to have PLAYS in the rows also. The B row has all numbers 1-15 located inside of it, the I row has all numbers 16-30 inside of it, the N row has all numbers 31-45 inside, the G row has all numbers 46-60 inside, and the O row has all numbers 61-75 inside. My question is what is the best way to set this board up? I am confused on how to set 15 different numbers equal to one key.
Thank you
Something like this, perhaps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <array>
#include <map>
#include <numeric>
#include <iomanip>

struct board {

    enum row_type { A, B, I, N, G, O }; // A = 0, B = 1 etc
    static constexpr std::size_t NUMBERS_PER_ROW = 15 ;

    // key: row   mapped value: array of numbers
    // https://en.cppreference.com/w/cpp/container/map
    // https://en.cppreference.com/w/cpp/container/array
    std::map< row_type, std::array<int,NUMBERS_PER_ROW> > plays ;

    board()
    {
        int n = 1 ; // numbers for the first row start at 1
        for( row_type row : { A, B, I, N, G, O } )
        {
            std::array<int,NUMBERS_PER_ROW> numbers ;

            // fill the array with numbers n, n+1 ...
            // https://en.cppreference.com/w/cpp/algorithm/iota
            std::iota( numbers.begin(), numbers.end(), n ) ;

            plays[row] = numbers ; // insert key, array pair into the map

            n += NUMBERS_PER_ROW ; // numbers for the next row start at this value
        }
    }

    // helper function to print the board
    friend std::ostream& operator<< ( std::ostream& stm, const board& brd )
    {
        static const std::string chars = "ABINGO" ;

        for( const auto& [row,numbers] : brd.plays )
        {
             stm << chars[row] << " [ " ;
             for( int n : numbers ) stm << std::setw(3) << n ;
             stm << " ]\n" ;
        }
        return stm ;
    }
};

int main()
{
     board brd ;
     std::cout << brd << '\n' ;
}

http://coliru.stacked-crooked.com/a/23ac4dae1c685388
Funny, Coliru acts different from cpp.sh -- the later does moans about line 40:
 In function 'std::ostream& operator<<(std::ostream&, const board&)':
40:26: error: expected unqualified-id before '[' token
40:26: error: expected ';' before '[' token
40:27: error: 'row' was not declared in this scope
40:31: error: 'numbers' was not declared in this scope
 In lambda function:
40:40: error: expected '{' before ':' token
 In function 'std::ostream& operator<<(std::ostream&, const board&)':
40:40: error: expected ';' before ':' token
40:40: error: expected primary-expression before ':' token
40:40: error: expected ')' before ':' token
40:40: error: expected primary-expression before ':' token
Structured bindings came with C++17 https://en.cppreference.com/w/cpp/language/structured_binding

This should work with C++11:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>
#include <array>
#include <map>
#include <numeric>
#include <iomanip>

struct board {

    enum row_type { A, B, I, N, G, O }; // A = 0, B = 1 etc
    static constexpr std::size_t NUMBERS_PER_ROW = 15 ;

    // key: row   mapped value: array of numbers
    // https://en.cppreference.com/w/cpp/container/map
    // https://en.cppreference.com/w/cpp/container/array
    std::map< row_type, std::array<int,NUMBERS_PER_ROW> > plays ;

    board()
    {
        int n = 1 ; // numbers for the first row start at 1
        for( row_type row : { A, B, I, N, G, O } )
        {
            std::array<int,NUMBERS_PER_ROW> numbers ;

            // fill the array with numbers n, n+1 ...
            // https://en.cppreference.com/w/cpp/algorithm/iota
            std::iota( numbers.begin(), numbers.end(), n ) ;

            plays[row] = numbers ; // insert key, array pair into the map

            n += NUMBERS_PER_ROW ; // numbers for the next row start at this value
        }
    }

    // helper function to print the board
    friend std::ostream& operator<< ( std::ostream& stm, const board& brd )
    {
        static const std::string chars = "ABINGO" ;

        for( const auto& pair : brd.plays )
        {
             const auto& row = pair.first ;
             const auto& numbers = pair.second ;
             
             stm << chars[row] << " [ " ;
             for( int n : numbers ) stm << std::setw(3) << n ;
             stm << " ]\n" ;
        }
        return stm ;
    }
};

int main()
{
     board brd ;
     std::cout << brd << '\n' ;
}

This should work with C++11:
It does.
Topic archived. No new replies allowed.