i was looking for the same thing, i found this simple code that works very well without spending tons of time trying to come up with your own solution:
<?php if ( has_nav_menu( ‘primary-menu’ ) ) { ?>
<div class=”nav-container”>
<?php wp_nav_menu( array( ‘theme_location’ => ‘primary-menu’ ) ); ?>
<?php get_search_form(); ?>
</div>
} ?>