Best method? to pass a bidimensional array with known values as a parameter to a function inside a library

You can't, that was my point. So, your 2 x std::array technique is no better than the template code that @jfjlaros posted here.

Also, the technique of passing a type-cast pointer and the array sizes is likely invalid per This Discussion.

How is this relevant to using std::array. Actually how all this is relevant? OP wants to pass multidimensional array to function, std::array makes is seamless (if platform supported) no fuss no trouble no headache, also std::array is just a wrapper so not expensive either.

It's relevant because of your previous comment:

My comment was to show the absurdity of your comment. Why do I need to pass different size arrays to the same function? Did OP ask for it?

No. But since OP claims to be writing a library (per title of thread), that would logically be the next request.

Don't understand your unwarranted hostility.

Makes two of us. Why using std::array suddenly appeared troublesome and why one cannot use template to have function accept different size std::arrays (not that any one asked) Artificial restrictions imposed on my suggestion for no apparent reason. Did I suggest something non viable? No.

I think it comes closer to the non-templated suggestion in post #4.

A templated version could look something like this:

template <size_t n, size_t m> void myf(std::array<std::array<int, n>, m> a) {
  // ...

Hi @killzone_kid
Sorry for the delay, I have been traveling due to my job, thus I've been away from my project PC.
Ok so, I am trying to adapt your example to run in library form, but I'm still experiencing issues. Perhaps you can give me the final push to get it done?

I see on your Wokwi example that you are employing the directive keyword "using" to declare the array using the std lib.
I need to be able to declare the array in the user .ino, and pass the array to the library , but I need the definition of the std function inside the library (so the user does not have to insert the definition in their program explicitly),, therefore I'm trying to move it inside the .h header.

The other thing I need is for the user to be able to pass the size of the rows and cols of the matrix into the function, so that it can index automatically through the function. But I also understand that since the array is known, the MyArr arr is a known matrix and it should be able to be indexed through the function, albeit I'm not sure from the function call void myf(MyArr a) how to determine/extract the [i][j] values needed to index inside the function, since I have not passed the [rows_x][cols_y] int values eplicitly so they can be used on the for loops. Maybe the user will have to pass the values explicitly matrix.myf(int rows, int cols, arr) in the user .cpp (.ino)?

.h

#ifndef  BDMX_TST_H
#define  BDMX_TST_H
#endif
#include <Arduino.h>
#include <array>
using myArr = std::array<std::array<int,rows_x>,cols_y>;  //construct the array function here so the user doesn't have to
class Matrix{ //within this class to instantiate

             private:

             public:   void myf(myArr a);    //declare the function to use inside .cpp
              
};

.cpp

#include <bdmx_tst.h>

void myf(myArr a){

     for(int i = 0; i < rows_x; i++) //x
        {
          for(int j = 0; j < cols_y; j++) //y
             {
               if((twodmatrix[i][j]) == true)
                 {
                  Serial.print("•  on"); 
                 }
                 else
                   {
                    Serial.print("• off");
                   }
             }
             Serial.println();
        }
}

user .cpp (.ino)

#include <bdmx_tst.h>
const int rows_x = 16;     //declared const to include into the arry function
const int cols_y = 8;   
//using myArr = std::array<std::array<int const,rows_x>,int const cols_y>;   <- moved out from here to the .h to make it transparent for the user
Matrix matrix;  //attempting func instantation here

void setup() {
  Serial.begin(115200);
           myArr arr[rows_x][cols_y] = {{1,0,0,0,0,0,0,0},     //either declare rows/cols here somehow, or write them separtely as additional parameters 
                                        {0,1,0,0,0,0,0,0},     //to the function, but it;d be preferrable to have them implicit into the array declaration 
                                        {1,1,0,0,0,0,0,0},
                                        {0,0,1,0,0,0,0,0},       
                                        {1,0,1,0,0,0,0,0},       
                                        {0,1,1,0,0,0,0,0},        
                                        {1,1,1,0,0,0,0,0},      
                                        {0,0,0,1,0,0,0,0},
                                        {1,0,0,1,0,0,0,0},
                                        {0,1,0,1,0,0,0,0},
                                        {0,1,1,1,0,0,0,0},
                                        {0,0,1,1,0,0,0,0},
                                        {1,0,1,1,0,0,0,0},
                                        {0,1,1,1,0,0,0,0},
                                        {1,1,1,1,0,0,0,0},
                                        {1,1,1,1,1,1,1,1}}; 
  Serial.print("The results are being displayed next: ");
  matrix.myf(arr);  //The function should execute automatically here
}

void loop(){delay(10);}

So, adding the const cols/rows into the std array function is not working well, nor moving the preprocessor directive using to the header.

bdmx_tst.h:11:33: error: 'myArr' has not been declared
              public:   void myf(myArr a);
                                 ^~~~~
R004.ino: In function 'void setup()':
R004:9:12: error: 'myArr' was not declared in this scope
            myArr arr[rows_x][cols_y] = {{1,0,0,0,0,0,0,0},
            ^~~~~
R004:26:14: error: 'arr' was not declared in this scope
   matrix.myf(arr);  //The function should execute automatically here
              ^~~]

It looks like moving the "using" directive to .h is creating much of the problem. How can I declare it properly for the lib model described here?
Thanks in advance for your time!

Why? Obviously this is wrong. You are basically trying to make 4 dimensional array. I suggest you start with reading about std::array and using

Hi guys,

For anyone wondering, a discusion with @jfjlaros on a separate thread yielded a good solution for the bidimensional matrix problem, I am sharing here for anyone that is interested in a working template solution :

https://forum.arduino.cc/t/re-best-method-to-pass-a-bidimensional-array-with-known-values-as-a-parameter-to-a-function-inside-a-library/1055136/8?u=edzamper

Thanks!

The link you provided will only work for the people that are part of that private discussion, so here is a summary.

And later...

The link you provided will only work for the people that are part of that private discussion, so here is a summary.

Oops, my bad.... closing this thread now. Thanks, everyone.