diff --git a/src/macro/Environment.cc b/src/macro/Environment.cc
index 46519e6c1253de2e10d33470fe3e8b0474e388c8..dad11ff66c3e0e2209137abab0497e8d6bb82632 100644
--- a/src/macro/Environment.cc
+++ b/src/macro/Environment.cc
@@ -118,7 +118,8 @@ Environment::print(ostream& output, const vector<string>& vars, int line, bool s
   if (vars.empty())
     {
       vector<string> variables_sorted;
-      ranges::copy(views::keys(variables), back_inserter(variables_sorted));
+      ranges::transform(variables, back_inserter(variables_sorted),
+                        &decltype(variables)::value_type::first);
       ranges::sort(variables_sorted, case_insensitive_string_less);
       for (const auto& it : variables_sorted)
         printVariable(output, it, line, save);
@@ -134,7 +135,8 @@ Environment::print(ostream& output, const vector<string>& vars, int line, bool s
   if (vars.empty())
     {
       vector<string> functions_sorted;
-      ranges::copy(views::keys(functions), back_inserter(functions_sorted));
+      ranges::transform(functions, back_inserter(functions_sorted),
+                        &decltype(functions)::value_type::first);
       ranges::sort(functions_sorted, case_insensitive_string_less);
       for (const auto& it : functions_sorted)
         printFunction(output, it, line, save);