# Code Style Request: More public members, pls

**URL:** <https://forum.juce.com/t/code-style-request-more-public-members-pls/50768>\
**Category:** General JUCE discussion\
**Created:** [March 28, 2022, 9:42pm UTC](https://forum.juce.com/t/code-style-request-more-public-members-pls/50768 "2022-03-28T21:42:54Z")\
**Posts on this page:** 5\
**Page:** 4

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [March 29, 2022, 5:53pm UTC](https://forum.juce.com/t/code-style-request-more-public-members-pls/50768/61 "2022-03-29T17:53:49Z")

</div>

so this basically makes some sort of array of type T, but without having to access the array with an index, but actually by its member’s name, right? really interesting concept. i never saw this before

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [March 29, 2022, 6:03pm UTC](https://forum.juce.com/t/code-style-request-more-public-members-pls/50768/62 "2022-03-29T18:03:14Z")

</div>

Not quite. [Structured bindings](https://en.cppreference.com/w/cpp/language/structured_binding) allow you to “bind” public members of a structure to a corresponding number of variables.

The variables don’t have to have the same name, so you could have

```cpp
const auto [width, height] = unpack (bounds);
// or
const auto [w, h] = unpack (bounds);
// or
const auto [length, thickness] = unpack (bounds);

```

It doesn’t make an array, and the type of the values depends on the types in the structure, hence the importance of using `auto`.

You can also get references to the members using:

```cpp
auto& [a, b] = unpack (bounds);

```

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [March 29, 2022, 6:07pm UTC](https://forum.juce.com/t/code-style-request-more-public-members-pls/50768/63 "2022-03-29T18:07:09Z")

</div>

awesome. yeah sounds like that could actually speed up quite some GUI code writing and the only cost is that the reader must know this c++ feature

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [March 29, 2022, 6:40pm UTC](https://forum.juce.com/t/code-style-request-more-public-members-pls/50768/64 "2022-03-29T18:40:41Z")

</div>

The drawback is that you must know the order of the members in the tuple, hence I would always prefer a struct where the members have names.  
So we are back to the original Rectangle, which is the solution I like best.  
IMHO it is not broken, no need to fix it.

---

<div class="post-metadata">

**Author:** ![nicolasdanet](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicolasdanet/32/56_2.png) [@nicolasdanet](https://forum.juce.com/u/nicolasdanet)\
**Post date:** [March 30, 2022, 6:58am UTC](https://forum.juce.com/t/code-style-request-more-public-members-pls/50768/65 "2022-03-30T06:58:50Z")

</div>

@daniel I’m agree, this is a serious drawback (as for std::Tuple).  
@PluginPenguin Thanks! I didn’t know that it could be done without modify the JUCE source.

I did a quick test for fun.

```auto
namespace std {

template <> struct tuple_size<juce::Rectangle<int>> : integral_constant<size_t, 2> {};

template <> struct tuple_element<0, juce::Rectangle<int>> { using type = int; };
template <> struct tuple_element<1, juce::Rectangle<int>> { using type = int; };

}

namespace juce {

template<std::size_t Index> std::tuple_element_t<Index, juce::Rectangle<int>> get (const juce::Rectangle<int>& r)
{
    if constexpr (Index == 0) return r.getWidth();
    if constexpr (Index == 1) return r.getHeight();
}

}

```

```auto
void MainComponent::resized()
{
    const auto [w, h] = getLocalBounds();
    
    DBG (w);
    DBG (h);
}

```

And it seems to work perfectly fine.

> **[Dummy/StructuredBinding at master · nicolasdanet/Dummy](https://github.com/nicolasdanet/Dummy/tree/master/StructuredBinding)**
>
> master/StructuredBinding

[Previous page](https://forum.juce.com/t/code-style-request-more-public-members-pls/50768.md?page=3)
