# Maps of int|real array

**URL:** <https://community.freefem.org/t/maps-of-int-real-array/957>\
**Category:** General Discussion\
**Created:** [April 30, 2021, 10:52pm UTC](https://community.freefem.org/t/maps-of-int-real-array/957 "2021-04-30T22:52:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)\
**Post date:** [April 30, 2021, 10:52pm UTC](https://community.freefem.org/t/maps-of-int-real-array/957/1 "2021-04-30T22:52:35Z")

</div>

Hello,

Do you think possible to extend the language to allow the declaration of maps of array like int[][string] or real[][string] ?

Best regards.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [May 2, 2021, 8:04am UTC](https://community.freefem.org/t/maps-of-int-real-array/957/2 "2021-05-02T08:04:13Z")

</div>

yes, but i don’t like is syntax.

and I am not sure to understand what you want,  
can you explain in C++ what is the key type of the map and the mapped value type.

remark: make a double as a key value is not a good idea due to roundoff error.

to day your can do

```
    real[string] mapr;
    int[string] mapi;

    mapr[2.15]= 6.6;
    mapi[2]= 7;
    // here 2.15 is cast in string "2.15" and 2 in string "2" automatically
```

---

<div class="post-metadata">

**Author:** ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)\
**Post date:** [May 2, 2021, 1:15pm UTC](https://community.freefem.org/t/maps-of-int-real-array/957/3 "2021-05-02T13:15:44Z")

</div>

we misunderstood each other, the key value is always either a string or a int. The idea is have these two objects :

> map\<string, int\>  
> map\<string, real\>  
> map\<string, string\>  
> map\<int, int\>  
> map\<int, real\>  
> map\<int, string\>

Best regards.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [May 3, 2021, 3:03pm UTC](https://community.freefem.org/t/maps-of-int-real-array/957/4 "2021-05-03T15:03:45Z")

</div>

Yes for

```
 map<string, int[]>
 map<string, real[]>
 map<string, string[]>

```

this syntaxe is clear

```
int[string][int] 
real[string][int] 
string[string][int] 

```

but for this other we can not used  
int[int][int]  
real[int][int]  
string[int][int]

because it is array of array not map .

---

<div class="post-metadata">

**Author:** ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)\
**Post date:** [May 4, 2021, 12:01am UTC](https://community.freefem.org/t/maps-of-int-real-array/957/5 "2021-05-04T00:01:50Z")

</div>

I better understand. Do you know when map\<string,T\> will be available ?  
Let’s suppose ID (from a medit or gmsh mesh file) be either an int or a string, the motivation comes from the need to store solid IDs according to materials IDs (that goes the same for surface IDs according to boundary condition IDs), ids are not necesserary 0-index and must be arbitrary “big”, it’d be a pity to not use a sparse structure for IDs such as maps.  
So that i could write :

> int[string][int] MaterialID;  
> MaterialID[“45757”] = [1214,2354,396,14];  
> MaterialID[“14664”] = [567,47787,12];

and

> cout\<\<"Size = "\<\<MaterialID.n\<\<endl;  
> cout\<\<MaterialID\<\<endl;

> Size = 2  
> 2  
> 1214 2354 396 14 4  
> 567 47787 12 3

> cout\<\<MaterialID[“14664”][2]\<\<endl;  
> cout\<\<MaterialID[“14664”].n\<\<endl;

> 12  
> 3

Best regards.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [May 4, 2021, 9:36am UTC](https://community.freefem.org/t/maps-of-int-real-array/957/6 "2021-05-04T09:36:31Z")

</div>

no today, It depend strongly of your need!

Best Regards,

Frédéric Hecht.
