0

I have a struct, and a mapping, like

struct Foo {
   string bar;
}
mapping(string => Foo) private valueToFoo;

I want to make sure that this value Foo for value baz does not exist before proceeding:

Foo memory foo = valueToFoo[_value];
require(!foo; "Such foo already exists");

Can I convert struct to bool?

3
  • you need to compare the string „bar“ if it is empty
    – Majd TL
    May 31, 2022 at 16:08
  • @MajdTL but if valueToFoo[_value] is not defined, will I be able to access bar?
    – mdmb
    Jun 1, 2022 at 10:53
  • Yes it is accessible and you don’t get undefined error like JavaScript
    – Majd TL
    Jun 1, 2022 at 17:56

0

Browse other questions tagged or ask your own question.