This is the functionality that the multi index was based around.
To get the name, simple add .value
to your key on return:
uint64_t primary_key() const { return key.value;} // key.VALUE
In the tutorial, they actually use a uint64_t for the secondary index. That's all eosio::name
is under the hood, a uint64_t. Granted they use it to represent an age by a number, but it's still the same type nonetheless.
https://developers.eos.io/eosio-home/docs/secondary-indices
uint64_t age;
uint64_t get_secondary_1() const { return age;} // secondary index
typedef eosio::multi_index<"people"_n, person,
indexed_by<"byage"_n, const_mem_fun<person, uint64_t, &person::get_secondary_1>>
> address_index;
In this tutorial, you can see the primary index is indeed an eosio::name type:
struct person {
name key;
std::string first_name;
std::string last_name;
std::string street;
std::string city;
std::string state;
uint64_t primary_key() const { return key.value;}
};